2019年1月18日 星期五

例題1-12 已知3點座標及導數 ,建立 Hermite 向後差除表

例題1-12 已知3點座標及導數如下

=================================
i       xi        f(xi)          f'(xi)
0      0.0      1.0000       1.0000
1      1.0      2.7183        2.7183
2      2.0      2.7183        2.7183
==================================
建立 Hermite 向後差除表
Hn(1.5) 之值
H'n(1.5) 之值


'''
To generate the coeffficients for
 * Hermite Interpolating Polynomial H on the distinct numbers
 * x0,x1,x2,...with f0,f1,f2,... and f'0,f'1,f'2...
 * based on the Newton backward divided-difference Algorithm
 * and output the divided_difference table for Hn(x).
'''
#x[30],z[30],q[30][30],f[30],ff[30];
x = [0 for i in range(30)]
z = [0 for i in range(30)]
f = [0 for i in range(30)]
q = [[0 for i in range(30)]  for j in range(30)];
ff = [[0 for i in range(30)]  for j in range(30)];
n=2+1
x=[0.0 , 1.0 ,2.0]
f=[1.000 , 2.7183 , 7.3891]
ff=[1.000 , 2.7183 , 7.3891]
print("i","\t", "z(i)","\t","f(i)","\t","f(i-1,i)","\t","f(i-2,i-1,i)","\t", "....................................");

for i in range (0,n):
    z[2*i]=x[i];
    z[2*i+1]=x[i];
    q[2*i][0]=f[i];
    q[2*i+1][0]=f[i];
    q[2*i+1][1]=ff[i];
    if(i !=0):
        q[2*i][1]=(q[2*i][0]-q[2*i-1][0])/(z[2*i]-z[2*i-1]);

    if(i==0):
        print(round(i, 4),"\t",round(z[i], 4), "\t" , round(q[i][0],4) );
    elif(i==1):
        print(round(i, 4),"\t",round(z[i], 4), "\t" , round(q[i][0],4) ,"\t",round(q[i][1],4) );

for i in range (2,2*n):
    print(round(i, 4),"\t",round(z[i], 4), "\t" , round(q[i][0],4) ,"\t",round(q[i][1],4),end="" );
    for j in range(2,i+1):
        q[i][j]=(q[i][j-1]-q[i-1][j-1])/(z[i]-z[i-j]);
        print("\t",round(q[i][j] ,4) , end="");
    print("");


======== RESTART: F:/2018-09勤益科大數值分析/數值分析/PYTHON/EX1-12.py ==========
i z(i)  f(i)          f(i-1,i) f(i-2,i-1,i) ....................................
0 0.0 1.0
1 0.0 1.0          1.0
2 1.0 2.7183 1.7183 0.7183
3 1.0 2.7183 2.7183 1.0          0.2817
4 2.0 7.3891 4.6708 1.9525 0.4762 0.0973
5 2.0 7.3891 7.3891 2.7183 0.7658 0.1448 0.0238
>>> 
Hn(x)= 1.0 + 1.0 (x-0.0) +  0.7183 (x-0.0)^2 +  0.2817 (x-0.0)^2 (x-1.0)
             + 0.0973 (x-0.0)^2 (x-1.0) ^2 + 0.0238 (x-0.0)^2 (x-1.0) ^2 (x-2.0)

沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...