需要一個驗證n次拉格朗日插值定理的源代碼,最好是C語言做的,C++的也可以,謝謝
熱心網友
抄一個給你,自己打不夠麻煩的#include#include#includetypedef struct data{ float x; float y;}Data;//變量x和函數值y的結構Data d[20];//最多二十組數據float f(int s,int t)//牛頓插值法,用以返回插商{ if(t==s+1) return (d[t]。y-d[s]。y)/(d[t]。x-d[s]。x); else return (f(s+1,t)-f(s,t-1))/(d[t]。x-d[s]。x); }float Newton(float x,int count){ int n; while(1) { coutn; if(ncount; if(countd[i]。x; coutd[i]。y; system("cls"); } coutx; while(1) { int choice=3; coutchoice;//取得用戶的選擇項 if(choice==2) { cout<<"你選擇了牛頓插值計算方法,其結果為:"; y=Newton(x,count);break;//調用相應的處理函數 } if(choice==1) { cout<<"你選擇了拉格朗日插值計算方法,其結果為:"; y=lagrange(x,count);break;//調用相應的處理函數 } if(choice==0) break; system("cls"); cout<<"輸入錯誤!!!!"<