📄 two.cpp
字号:
#include <math.h>
#include <iostream.h>
#include<stdio.h>
#include<iomanip.h>
# define PAI 3.14159265358979323846
main()
{
long double T[11],A[9],x1[11],x2[11];
for(int i=0;i<=10;i++)
{
x1[i]=i*PAI/20;
if(i<9)
x2[i]=(i+0.5)*PAI/20;
}
for(int j=0;j<=10;j++)
{
T[j]=sin(x1[j]);
if(j<9)
A[j]=sin(x2[j]);
}
long double a,b,c,L1[9],L2[9];
for(int h=0;h<9;h++)
{
a=x1[h];
b=x1[h+1];
c=x1[h+2];
L1[h]=T[h]*(x2[h]-b)/(a-b)+T[h+1]*(x2[h]-a)/(b-a);
L2[h]=T[h]*(x2[h]-b)*(x2[h]-c)/(a-b)/(a-c)+
T[h+1]*(x2[h]-a)*(x2[h]-c)/(b-a)/(b-c)+
T[h+2]*(x2[h]-b)*(x2[h]-a)/(c-b)/(c-a);
}
cout<<"函数表:"<<endl;
cout<<"xi sinxi"<<endl;
for(i=0;i<=10;i++)
{
printf("%10.9f %10.9f",x1[i],T[i]);
cout<<endl;
}
cout<<"插值点\t\t真值:\t 一次插值\t误差\t 二次插值\t 误差"<<endl;
for(i=0;i<=8;i++)
{
printf("%10.9f %10.9f %10.9f %10.9f %10.9f %10.9f"
,x2[i],A[i],L1[i],fabs(A[i]-L1[i]),L2[i],fabs(A[i]-L2[i]));
cout<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -