2019年2月12日 星期二

習題2-2 已知 非線性方程式 exp(x)-3x^2=0 在 -1.0 與 +5.5之間有幾個根存在??

習題2-2 已知

非線性方程式 exp(x)-3x^2=0

在 -1.0 與 +5.5之間有幾個根存在??



import math

#define  math.exp(x) - 3.0*math.pow(x,2))
#====================================
def f_cal(x) :
    temp= ( math.exp(x) - 3.0*x*x )
    return temp

a=-1.0
b=5.5
x=a
i=1
print(" i \t\tx \t f(x)\n")

while x<=b:
    s = "{%5d} {%8.2f} {%2.5f}" %(i,x,f_cal(x))
    print(s)
    i+=1
    x=x+0.1



在  -0.5與 -0.4 之間有一根
在  0.9與 1.0 之間有一根
在  3.7與  3.8 之間有一根



輸出畫面

======== RESTART: H:/2018-09勤益科大數值分析/數值分析/PYTHON/Pr2-2.py ===========
 i x f(x)

{    1} {   -1.00} {-2.63212}
{    2} {   -0.90} {-2.02343}
{    3} {   -0.80} {-1.47067}
{    4} {   -0.70} {-0.97341}
{    5} {   -0.60} {-0.53119}
{    6} {   -0.50} {-0.14347}
{    7} {   -0.40} {0.19032}
{    8} {   -0.30} {0.47082}
{    9} {   -0.20} {0.69873}
{   10} {   -0.10} {0.87484}
{   11} {   -0.00} {1.00000}
{   12} {    0.10} {1.07517}
{   13} {    0.20} {1.10140}
{   14} {    0.30} {1.07986}
{   15} {    0.40} {1.01182}
{   16} {    0.50} {0.89872}
{   17} {    0.60} {0.74212}
{   18} {    0.70} {0.54375}
{   19} {    0.80} {0.30554}
{   20} {    0.90} {0.02960}
{   21} {    1.00} {-0.28172}
{   22} {    1.10} {-0.62583}
{   23} {    1.20} {-0.99988}
{   24} {    1.30} {-1.40070}
{   25} {    1.40} {-1.82480}
{   26} {    1.50} {-2.26831}
{   27} {    1.60} {-2.72697}
{   28} {    1.70} {-3.19605}
{   29} {    1.80} {-3.67035}
{   30} {    1.90} {-4.14411}
{   31} {    2.00} {-4.61094}
{   32} {    2.10} {-5.06383}
{   33} {    2.20} {-5.49499}
{   34} {    2.30} {-5.89582}
{   35} {    2.40} {-6.25682}
{   36} {    2.50} {-6.56751}
{   37} {    2.60} {-6.81626}
{   38} {    2.70} {-6.99027}
{   39} {    2.80} {-7.07535}
{   40} {    2.90} {-7.05585}
{   41} {    3.00} {-6.91446}
{   42} {    3.10} {-6.63205}
{   43} {    3.20} {-6.18747}
{   44} {    3.30} {-5.55736}
{   45} {    3.40} {-4.71590}
{   46} {    3.50} {-3.63455}
{   47} {    3.60} {-2.28177}
{   48} {    3.70} {-0.62270}
{   49} {    3.80} {1.38118}
{   50} {    3.90} {3.77245}
{   51} {    4.00} {6.59815}
{   52} {    4.10} {9.91029}
{   53} {    4.20} {13.76633}
{   54} {    4.30} {18.22979}
{   55} {    4.40} {23.37087}
{   56} {    4.50} {29.26713}
{   57} {    4.60} {36.00432}
{   58} {    4.70} {43.67717}
{   59} {    4.80} {52.39042}
{   60} {    4.90} {62.25978}
{   61} {    5.00} {73.41316}
{   62} {    5.10} {85.99191}
{   63} {    5.20} {100.15224}
{   64} {    5.30} {116.06681}
{   65} {    5.40} {133.92642}
{   66} {    5.50} {153.94193}
>>> 

沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...