📄 d2r3.cpp
字号:
# include<iostream.h>
# include<math.h>
# include<iomanip.h>
void main()
{
double x[21], y[21], y2[21],pi,yp1,ypn ;
int n, i;
//program d2r3
//driver for routine spline
n = 20;
pi = 3.1415926;
//生成插值数组
for (i = 1;i<=20;i++)
{
x[i] = i * pi / n;
y[i] = sin(x[i]);
}
//用三次样条函数计算二阶导数
yp1 = cos(x[1]);
ypn = cos(x[n]);
cout<<endl;
cout<<"Second-derivative for sin(x) from 0 to pi"<<endl;
spline(x, y, n, yp1, ypn, y2);
//验证计算结果
cout<<" spline actual"<<endl;
cout<<" angle 2nd deriv 2nd deriv"<<endl;
for( i = 1;i<=n;i++)
{
cout<<setprecision(6)<<setiosflags(ios::fixed);
cout<<setw(14)<<x[i];
cout<<setw(14)<<y2[i];
cout<<setw(14)<<-sin(x[i])<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -