• 大小: 237KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: C/C++
  • 标签: 计算方法  c++  

资源简介

计算方法中三次样条插值法的c++实现,计算方法中很好的实例

资源截图

代码片段和文件信息

#include 
#include 

void sanciytcz();
void extern zhuigf(double *ldouble*udouble*gint N);

int main()
{
sanciytcz();
return 0;
}

void sanciytcz()
{
int Ntype;
double y01=0y02=0yn1=0yn2=0;
cout<<“请输入插值点的个数:“;
cin>>N;
N--;
double *x=new double[N+1];
double *y=new double[N+1];
double *h=new double[N+1];
double *u=new double[N+1];
double *l=new double[N+1];
double *d=new double[N+1];

for(int i=0;i<=N;i++)
{
cout<<“第“< cin>>x[i]>>y[i];
}

cout<<“请输入这是第几类问题(1 or 2):“;
cin>>type;

if(type==1)
{
cout<<“端点条件x0处的一阶导数为:“;
cin>>y01;
cout<<“端点条件x“< cin>>yn1;
}
else
{
cout<<“端点条件x0处的二阶导数为:“;
cin>>y02;
cout<<“端点条件x“< cin>>yn2;
}


for(i=1;i<=N;i++)
{
h[i]=x[i]-x[i-1];
        cout<<“h[“< }



if(type==1)
{
l[0]=1;
u[N]=1;
}
else
{
l[0]=0;
u[N]=0;
}
for(i=1;i<=N-1;i++)
{
l[i]=h[i+1]/(h[i]+h[i+1]);
u[i]=1-l[i];
d[i]=6/(h[i]+h[i+1])*((y[i+1]-y[i])/h[i+1]-(y[i]-y[i-1])/h[i]);
}

if(type==1)
{
d[0]=6/h[1]*((y[1]-y[0])/(x[1]-x[0])-y01);
d[N]=6/h[N]*(yn1-(y[N]-y[N-1])/(x[N]-x[N-1]));
}
else
{
d[0]=2*y02;
d[N]=2*yn2;
}


for(i=0;i<=N-1;i++)
{
cout<<“l[“< }
for(i=1;i<=N;i++)
{
cout<<“u[“< }
for(i=0;i<=N;i++)
{
cout<<“d[“< }


zhuigf(uldN+1);

double aresult;
cout<<“请输入要求的数:“;
cin>>a;
int IP=1;
for(int j=1;j<=N;j++)
{
if(a>=x[j-1]&&a<=x[j])  
{
IP=-1;
i=j;
break;
}
else IP=1;
}
if(IP==1)
{
cout< }
else
{
result=(x[i]-a)*(x[i]-a)*(x[i]-a)/6/h[i]*d[i-1]
+(a-x[i-1])*(a-x[i-1])*(a-x[i-1])/6/h[i]*d[i]
+(y[i-1]-d[i-1]/6*h[i]*h[i])*(x[i]-a)/h[i]
+(y[i]-d[i]/6*h[i]*h[i])*(a-x[i-1])/h[i];

cout<<“===================\n“<<“结果为:“< }




delete[]x;
delete[]y;
delete[]h;
delete[]u;
delete[]l;
delete[]d;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      13958  2008-12-04 19:46  三次样条插值法\Debug\sanciytczf.obj

     文件      41984  2008-12-04 19:46  三次样条插值法\Debug\vc60.idb

     文件      61440  2008-12-04 19:46  三次样条插值法\Debug\vc60.pdb

     文件       6545  2008-12-04 19:40  三次样条插值法\Debug\zhuigf.obj

     文件     233561  2008-12-04 19:46  三次样条插值法\Debug\三次样条插值法.exe

     文件     286472  2008-12-04 19:46  三次样条插值法\Debug\三次样条插值法.ilk

     文件     186960  2008-11-29 15:33  三次样条插值法\Debug\三次样条插值法.pch

     文件     558080  2008-12-04 19:46  三次样条插值法\Debug\三次样条插值法.pdb

     文件       2197  2008-12-04 19:47  三次样条插值法\sanciytczf.cpp

     文件       1001  2008-12-04 19:40  三次样条插值法\zhuigf.cpp

     文件       4439  2008-11-29 15:19  三次样条插值法\三次样条插值法.dsp

     文件        536  2008-11-29 14:04  三次样条插值法\三次样条插值法.dsw

     文件      41984  2008-12-04 19:47  三次样条插值法\三次样条插值法.ncb

     文件      53760  2008-12-04 19:47  三次样条插值法\三次样条插值法.opt

     文件       1364  2008-12-04 19:46  三次样条插值法\三次样条插值法.plg

     目录          0  2008-12-04 19:46  三次样条插值法\Debug

     目录          0  2008-12-04 19:47  三次样条插值法

----------- ---------  ---------- -----  ----

              1494281                    17


评论

共有 条评论