c2.cpp
资源名称:数值分析课程设计.zip [点击查看]
上传用户:zhdd911129
上传日期:2007-05-11
资源大小:722k
文件大小:1k
源码类别:
matlab例程
开发平台:
Matlab
- //C2
- //Interpolate,using Langrang Methom
- #include <iostream.h>
- #include <time.h>
- //Langrange polynomial
- double LP(double x,double *ax,double *ay,int n)
- {
- double sum=0,Tsum=1;
- int i,j;
- for (i=0;i<n;i++)
- {
- for (j=0;j<n;j++)
- {
- if (j!=i)
- Tsum=Tsum*(x-ax[j])/(ax[i]-ax[j]);
- }
- sum=sum+Tsum*ay[i];
- Tsum=1;
- }
- return sum;
- }
- void main()
- {
- double ax[]={0.56160,0.56280,0.56401,0.56521},ay[]={0.82741,0.82659,0.82577,0.82495},x=0.5635;
- int n=4;
- cout<<"The value at that point is: "<<LP(x,ax,ay,n)<<endl;
- cin>>n;
- }
- //运行结果:0.826116,Lagrange实现并不困难,
- //但如要改变节点数,将会带来非常多的麻烦