求助:求三次样条插值函数的C++程序
问题描述:
求助:求三次样条插值函数的C++程序
已知:
α 30°40°50°60°70°80°90°
m 2.73 2.14 1.751.491.281.131.00
n 0.49 0.57 0.640.720.800.891.00
用三次样条差值函数求对于不同的α所对应的m、n的值,求此三次样条差值函数的C++程序.
答
#include
#include
using namespace std;
const int MAX = 50;
float x[MAX],y[MAX],h[MAX];
float c[MAX],a[MAX],fxym[MAX];
float f(int x1,int x2,int x3){
float a = (y[x3] - y[x2]) / (x[x3] - x[x2]);
float b = (y[x2] - y[x1]) / (x[x2] - x[x1]);
return (a - b)/(x[x3] - x[x1]);
} //求差分
void cal_m(int n){ //用追赶法求解出弯矩向量M……
float B[MAX];
B[0] = c[0] / 2;
for(int i = 1; i B[i] = c[i] / (2 - a[i]*B[i-1]);
fxym[0] = fxym[0] / 2;
for(i = 1; i = 0; i--)
fxym[i] = fxym[i] - B[i]*fxym[i+1];
}
void printout(int n);
int main(){
int n,i; char ch;
do{
coutn;
for(i = 0; i