例題1-10 牛頓向後差除法
已知4點座標
n=4
x f(x)
==========
1.0 0.0
2.0 0.693
3.0 1.099
4.0 1.386
求牛頓向後差除表
'''
EX1-10-1.py
Code for NEWTON'S BACKWARD DIFFERENCE METHOD in Python Programming
n=4
x f(x)
==========
1.0 0.0
2.0 0.693
3.0 1.099
4.0 1.386
'''
import math
def fact(a):
fac = 1.0
if (a == 0):
return (1.0)
else:
fac = a * fact(a-1)
return(fac)
#++++++++++++++++++++++++++++++
n=4
x= [0.0 for i in range(0,n)] #x [n] 矩陣
y= [ [0.0 for i in range(n)] for j in range(n) ] #[n] * [n] 矩陣
x=[ 1.0 , 2.0 , 3.0 ,4.0]
y=[[ 0.0 , 0.693 , 1.099 , 1.386],
[0.0 , 0.0 , 0.0, 0.0 ],
[0.0 , 0.0 , 0.0, 0.0],
[0.0 , 0.0 , 0.0, 0.0],
[0.0 , 0.0, 0.0, 0.0] ]
print("\nhow many record you will be enter: ",n)
print("\n\nenter the value of x%d: ")
for i in range (len(x)) :
print( '\t',round(x[i],4))
print()
k=0
print("\n\nenter the value of f(x): ")
for i in range (len(x)) :
print( '\t',i,"\t\t",round( y[k][i],4))
print()
p=1.5
print("\n\nEnter X for finding f(x): ",p)
for i in range(1,n):
#print(i,'\t',end='')
for j in range (i , n):
#print(j,'\t',end='')
y[i][j]= (y[i-1][j]-y[i-1][j-1]) / (x[j]-x[j-i]);
print(round( y[i][j],4),end=',')
print("\n_____________________________________________________\n")
print("\n x(i)\t y(i) y1(i) y2(i) y3(i) y4(i)")
print("\n_____________________________________________________\n")
for i in range (0 , n):
print("\n {%.4f}" %(x[i]),end='')
for j in range(0 , i+1):
print(" ",end='')
print(" {%.4f}" %(y[j][i]),end='')
print("\n");
======== RESTART: F:/2018-09勤益科大數值分析/數值分析/PYTHON/Ex1-10-1.py ==========
how many record you will be enter: 4
enter the value of x%d:
1.0
2.0
3.0
4.0
enter the value of f(x):
0 0.0
1 0.693
2 1.099
3 1.386
Enter X for finding f(x): 1.5
0.693,0.406,0.287,-0.1435,-0.0595,0.028,
_____________________________________________________
x(i) y(i) y1(i) y2(i) y3(i) y4(i)
_____________________________________________________
{1.0000} {0.0000}
{2.0000} {0.6930} {0.6930}
{3.0000} {1.0990} {0.4060} {-0.1435}
{4.0000} {1.3860} {0.2870} {-0.0595} {0.0280}
>>>
訂閱:
張貼留言 (Atom)
WOKWI DHT22 & LED , Node-Red + SQLite database
WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...
-
課程講義 下載 11/20 1) PPT 下載 + 程式下載 http://www.mediafire.com/file/cru4py7e8pptfda/106%E5%8B%A4%E7%9B%8A2-1.rar 11/27 2) PPT 下載...
-
• 認 識 PreFix、InFix、PostFix PreFix(前序式):* + 1 2 + 3 4 InFix(中序式): (1+2)*(3+4) PostFix(後序式):1 2 + 3 4 + * 後 序式的運算 例如: 運算時由 後序式的...
沒有留言:
張貼留言