2019年2月24日 星期日

Julia語言 EX2-2 f(x) = (0.0000115*pow(x,2)+0.000014*pow(x,1.5)-0.01962) 利用二分法求解

Julia語言 EX2-2  f(x) = (0.0000115*pow(x,2)+0.000014*pow(x,1.5)-0.01962) 利用二分法求解


using Printf

#==============================================================
Arithmetic Operators
The following arithmetic operators are supported on all primitive numeric types:

Expression Name Description
+x unary plus the identity operation
-x unary minus maps values to their additive inverses
x + y binary plus performs addition
x - y binary minus performs subtraction
x * y times performs multiplication
x / y divide performs division
x ÷ y integer divide x / y, truncated to an integer
x \ y inverse divide equivalent to y / x
x ^ y power raises x to the yth power
x % y remainder equivalent to rem(x,y)
==============================================================#

function fx(x::Float64) # 原非線性方程式
    #( (1.15*10^(-5)*(x^2)) + (1.4*10^(-5)*x) - (1.962*10^(-2)) )
    y= (0.0000115*(x^2)+(0.000014*(x^1.5)) - 0.1962)
    return ( y )
end

a=100.0
b=200.0
x=a
println(" i\t  x\t   f(x)");
i=1
while (x<=b)
    s=@sprintf("%2d\t%5.2f\t%10.5f",i,x,fx(x))
    println(s)
    x=x+1.0
    i+=1
end

a=124.0
b=125.0
x=a
println(" i\t  x\t   f(x)");
i=1
while (x<=b)
    s=@sprintf("%2d\t%5.2f\t%10.5f",i,x,fx(x))
    println(s)
    x=x+0.001
    i+=1
end


i   x    f(x)
 1 100.00   -0.06720
 2 101.00   -0.06468
 3 102.00   -0.06213
 4 103.00   -0.05956
 5 104.00   -0.05697
 6 105.00   -0.05435
 7 106.00   -0.05171
 8 107.00   -0.04904
 9 108.00   -0.04635
10 109.00   -0.04364
11 110.00   -0.04090
12 111.00   -0.03814
13 112.00   -0.03535
14 113.00   -0.03254
15 114.00   -0.02971
16 115.00   -0.02685
17 116.00   -0.02396
18 117.00   -0.02106
19 118.00   -0.01813
20 119.00   -0.01517
21 120.00   -0.01220
22 121.00   -0.00919
23 122.00   -0.00617
24 123.00   -0.00312
25 124.00   -0.00004
26 125.00    0.00305
27 126.00    0.00617
28 127.00    0.00932
29 128.00    0.01249
30 129.00    0.01568
31 130.00    0.01890
32 131.00    0.02214
33 132.00    0.02541
34 133.00    0.02870
35 134.00    0.03201
36 135.00    0.03535
37 136.00    0.03871
38 137.00    0.04209
39 138.00    0.04550
40 139.00    0.04893
41 140.00    0.05239
42 141.00    0.05587
43 142.00    0.05938
44 143.00    0.06290
45 144.00    0.06646
46 145.00    0.07003
47 146.00    0.07363
48 147.00    0.07726
49 148.00    0.08090
50 149.00    0.08457
51 150.00    0.08827
52 151.00    0.09199
...................
94 193.00    0.26970
95 194.00    0.27444
96 195.00    0.27921
97 196.00    0.28400
98 197.00    0.28881
99 198.00    0.29365
100 199.00    0.29851
101 200.00    0.30340
 i   x    f(x)
 1 124.00   -0.00004
 2 124.00   -0.00004
 3 124.00   -0.00004
 4 124.00   -0.00004
 5 124.00   -0.00003
 6 124.01   -0.00003
 7 124.01   -0.00003
 8 124.01   -0.00002
 9 124.01   -0.00002
10 124.01   -0.00002
11 124.01   -0.00001
12 124.01   -0.00001
13 124.01   -0.00001
14 124.01   -0.00000
15 124.01   -0.00000
16 124.02    0.00000
17 124.02    0.00000
18 124.02    0.00001
19 124.02    0.00001
20 124.02    0.00001
21 124.02    0.00002
22 124.02    0.00002
23 124.02    0.00002
24 124.02    0.00003
25 124.02    0.00003
26 124.03    0.00003
27 124.03    0.00004
28 124.03    0.00004
29 124.03    0.00004
30 124.03    0.00004
31 124.03    0.00005
32 124.03    0.00005
33 124.03    0.00005
34 124.03    0.00006
35 124.03    0.00006
36 124.04    0.00006
37 124.04    0.00007
38 124.04    0.00007
39 124.04    0.00007
40 124.04    0.00008
41 124.04    0.00008
42 124.04    0.00008
43 124.04    0.00008
44 124.04    0.00009
45 124.04    0.00009
46 124.05    0.00009
47 124.05    0.00010
48 124.05    0.00010
49 124.05    0.00010
50 124.05    0.00011
51 124.05    0.00011
52 124.05    0.00011
53 124.05    0.00012
54 124.05    0.00012
55 124.05    0.00012
56 124.06    0.00013
57 124.06    0.00013
58 124.06    0.00013
59 124.06    0.00013
..........................
994 124.99    0.00303
995 124.99    0.00303
996 125.00    0.00304
997 125.00    0.00304
998 125.00    0.00304
999 125.00    0.00305
1000 125.00    0.00305




沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...