输入文件zuixiaoercheng_input.txt中内容:
5 3
-2 -1 0 1 2
-0.1 0.1 0.4 0.9 1.6
代码部分:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#define p(k) (p+(k)*m)
#define pkx(k) (pkx+(k)*n)
double *x,*f,*p,*a,*b,*d,*pkx,*sx,*xishu;
int m,n;
void zhengjiaonihe();
void size(int *m,int *n);
void input(double x[],double f[],int m,int n);
void output(int n,double pkx[],double xishu[],double R);
double NeiJi(double *F,double *G,double *W);
void GetPk(int k);
void GetXiShu(int k);
double Wucha(int k);
void main()
{
zhengjiaonihe();
system("pause");
}
void zhengjiaonihe()
{
int k,i,j;
double t,R;
printf("\n本程序是用正交函数作最小二乘拟合\n");
size(&m,&n);
x=(double *)malloc(sizeof(double)*m);
f=(double *)malloc(sizeof(double)*m);
p=(double *)malloc(sizeof(double)*m*n);
a=(double *)malloc(sizeof(double)*n);
b=(double *)malloc(sizeof(double)*n);
d=(double *)malloc(sizeof(double)*n);
pkx=(double *)malloc(sizeof(double)*n*n);
sx=(double *)malloc(sizeof(double)*m);
xishu=(double *)malloc(sizeof(double)*n);
input(x,f,m,n);
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
pkx(i)[j]=0; // pkx 初始化
}
for (k=0;k<m;k++)
{
p(0)[k]=1; // P0(x)=1;
}
pkx(0)[0]=1;