-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolinom.kojo
18 lines (14 loc) · 1.3 KB
/
polinom.kojo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// roots: -3 and -1
def fun(x: Double) = x*x*x + 5*x*x + 7*x + 3 //> def fun(x: Double): Double
assert(fun(-3) == 0)
assert(fun(-1) == 0)
// fun(x) = (x+1)^2 (x+3)
def fu2(x: Double) = x*x*x - 5*x*x + 7*x - 3 //> def fu2(x: Double): Double
assert(fu2(3) == 0)
assert(fu2(1) == 0)
val range = 50 //> val range: Int = 50
val r = 10.0 //> val r: Double = 10.0
val all = for(x <- -range to range) yield (x/r, round(fun(x/r),3)) //> val all: IndexedSeq[(Double, Double)] = Vector((-5.0,-32.0), (-4.9,-28.899), (-4.8,-25.992), (-4.7,-23.273), (-4.6,-20.736), (-4.5,-18.375), (-4.4,-16.184), (-4.3,-14.157), (-4.2,-12.288), (-4.1,-10.571), (-4.0,-9.0), (-3.9,-7.569), (-3.8,-6.272), (-3.7,-5.103), (-3.6,-4.056), (-3.5,-3.125), (-3.4,-2.304), (-3.3,-1.587), (-3.2,-0.968), (-3.1,-0.441), (-3.0,0.0), (-2.9,0.361), (-2.8,0.648), (-2.7,0.867), (-2.6,1.024), (-2.5,1.125), (-2.4,1.176), (-2.3,1.183), (-2.2,1.152), (-2.1,1.089), (-2.0,1.0), (-1.9,0.891), (-1.8,0.768), (-1.7,0.637), (-1.6,0.504), (-1.5,0.375), (-1.4,0.256), (-1.3,0.153), (-1.2,0.072), (-1.1,0.019), (-1.0,0.0), (-0.9,0.021), (-0.8,0.088), (-0.7,0.207), (-0.6,0.384), (-0.5,0.625), (-0.4,0.936), (-0.3,1.323), (-0.2,1.792), (-0.1,2.349), (0.0,3.0), (0.1,3.751), (0.2,4...
clearOutput
all.foreach(println)
math.sqrt(3) + math.sqrt(2) //> val res17: Double = 3.1462643699419726