资源描述
2013-2014 (1)专业课程实践论文等距节点插值公式一、算法理论将Newton差商插值多项式中各阶差商用相应差分替代,就可得到各种形 式的等距节点插值公式。如果节点错误!未找到弓I用源。要计算错误!未找到引用源。附近点x的t (t -1)(t - k )h k+1,得函数f (x)值,可令错误!未找到引用源。于是o(x )=廿k+1j=0Nn(X0 + th )= f + t 岂t(t - 1)2!A 2 f + +01 (t-D (t- + D A nf n!称为Newton前插公式。如果要求表示函数在X附近的值f (x)错误!未找到引用源。此时应用 nNewton插值公式,插值点应按错误!未找到引用源。的次序排列,有N(x)=f (x )+f x)+f x,x , xnnnn-1nnn-1n-2n做变换错误!未找到引用源。带入公式得(x -x )G-x )+f lx ,x,x (x-x )(x-x )n1,Xn-1nn-1t (t +1) (t + n -1)+V nfn(x + th )= f +1 Af + gy V 2 f nnn2!为Newton后插公式。二、算法框图克小输人捅唱fl.区陶内三、算法程序class Interpolationpublic:Int erpola ti on(in t num, double x1, double x2, double func); double ComputeForwardValue(double x);In te rpola ti on();private:void GetF orwardTable();private:int m_num;double m_x1, m_x2;double m_step;double* m_func;double* m_ftable;#include iostream#include limitsusing namespace std;#define NUM 11#define MIN 0#define MAX 10int main()double funcNUM=0,1,4,9,16,25,36,49,64,81,100;double x1=MIN, x2=MAX, x;int num=NUM;char flag=Y;Int erpola tion test( num, x1, x2, func);while (flag=Y)coutInput x:;cinx;if (!cin)cin.clear();cin.ignore(numeric_limitsint: :max(), n);continue;if(xx2)coutInvalid input: xendl;coutOnly the number between x1=i; j)m_ft ablej = m_ft ablej -m_ft ablejT;double Interpolation:ComputeForwardValue(double x)double* coef;double result, t;int i;coef = new doublem_num;t = (x-m_x1)/m_s tep;for (i=1, coef0=1; im_num; +i)coefi = coef iT*(t-i+1)/i;for (i=0, result=0; im_num; +i)result += m_ftablei*coefi;delete coef;return result;四、算法实现例1.当错误!未找到弓|用源。时求错误!未找到引用源。在范围错误!未找 到引用源。内任意错误!未找到弓I用源。的值。解:(1) 在程序中输入11个样本:0,1,4,9,16,25,36,49,64,81 ,100且输入MIN :0,MAX :10,样本容量:11。(2) 在运行程序中输入范围内的任意x的值如1.2,1.4等。(3) 程序提示答案和提示是否继续,是则输入大写Y,否则输入大写N。个taw C:Wind wssystem32cmd .ex已Input x: 1.2Forward interpolation ualue: 1.4424Do you uant to process? please inputVInput x: 1.4Forward interpolation ualue: 1.9628Do you uant to process? please inputNPress any key to cont inue .例2.当给出15个f :n1.3&1.4 & 1.58,1.69,1.81,1.94,2.10,2.2 &2.50,2.76,3.06,3.41,3.83, 4.33,4.93,且给出范围:错误!未找到引用源。求出任意错误!未找到引用源。的值。 解:(1)给出15个题目上显示的值:1.3&1.4 & 1.5&1.69,1.81,1.94,2.10,2.28,2.50,2.76,3.06,3.41,3.83, 4.33,4.93,且输入 MIN: 4000, MAX :11000,样本容量:15。(2)在运行程序中输入范围内的任意错误味找到引用源。的值,如:1001,5200等。(3)程序提示答案和提示是否继续,是则输入大写Y,否则输入大写N。raw C:Wind owssystem32cTnd .exeInput x: 4001Forward interpolat ion value: 1.3747Do ijou want to process? please input :VInput x: 5200Forward interpolat ion value: 1.61375Do ijou want to process? please input :VInput x: 55555555Inualid input: 5.55556e+007Only the number betueen 4000 and 11000 is ualidDo you want to process? please input :NPress ani/ key to continue .
展开阅读全文