?? 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 + -