Julia語言 EX2-2 f(x) = (0.0000115*pow(x,2)+0.000014*pow(x,1.5)-0.01962) 利用二分法求解---(a) 測試根的範圍
using Printf
function f(x::Float64)
return (0.0000115*(x^2) + 0.000014*(x^1.5)- 0.01962)
end
#define MAX 50 /* maximum iterations */
#define TOL 0.001 /* tolerance */
MAX=150
TOL=0.001
i=1
a=0.0
b=50.0
x=a
s=@sprintf(" i\t\tx\t\t\tf(x)")
println(s)
while(x<=b)
s=@sprintf("%2d\t\t%9.6lf\t\t%9.6lf", i,x,f(x))
println(s)
i+=1
x+=0.1
end
a=0.0 , b=50.0的範圍
輸出畫面
i x f(x)
1 0.000000 -0.019620
2 0.100000 -0.019619
................................................
140 13.900000 -0.016673
141 14.000000 -0.016633
142 14.100000 -0.016592
143 14.200000 -0.016552
144 14.300000 -0.016511
145 14.400000 -0.016470
146 14.500000 -0.016429
................................................
357 35.600000 -0.002072
358 35.700000 -0.001977
359 35.800000 -0.001882
360 35.900000 -0.001787
361 36.000000 -0.001692
362 36.100000 -0.001596
363 36.200000 -0.001501
364 36.300000 -0.001405
365 36.400000 -0.001308
366 36.500000 -0.001212
367 36.600000 -0.001115
368 36.700000 -0.001018
369 36.800000 -0.000921
370 36.900000 -0.000823
371 37.000000 -0.000726
372 37.100000 -0.000628
373 37.200000 -0.000529
374 37.300000 -0.000431
375 37.400000 -0.000332
376 37.500000 -0.000233
377 37.600000 -0.000134
378 37.700000 -0.000034
379 37.800000 0.000065
380 37.900000 0.000165
381 38.000000 0.000265
382 38.100000 0.000366
383 38.200000 0.000467
384 38.300000 0.000568
385 38.400000 0.000669
386 38.500000 0.000770
387 38.600000 0.000872
.................................................
493 49.200000 0.013049
494 49.300000 0.013177
495 49.400000 0.013305
496 49.500000 0.013434
497 49.600000 0.013562
498 49.700000 0.013691
499 49.800000 0.013821
500 49.900000 0.013950
沒有留言:
張貼留言