📄 超定方程组解法.txt
字号:
#include <stdio.h>
#include <stdlib.h>
#define M 5
#define N 3
#define DIM N
extern int gcpelim( int process, double AN[DIM][DIM],double a[DIM]);
void mvfitgn(double A[M][N],double y[M],double a[N])
{
int i,j,l;
static double AN[DIM][DIM],aa;
printf("overdetermind equations:\n");
for(i=0;i<M;i++)
{for(j=0;j<N;j++) printf("%10.5f",A[i][j]);
printf(" %10.5f\n",y[i]);
}
printf("normal equations:\n");
for(i=0;i<DIM;i++)
{
for(j=0;j<=i;j++)
{
aa=0.0;
for(l=0;l<M;l++) aa=aa+A[l][i]*A[l][j];
AN[i][j]=aa; AN[j][i]=aa;
}
aa=0.0;
for(l=0;l<M;l++) aa=aa+A[l][i]*y[l];
a[i]=aa;
}
for(i=0;i<DIM;i++)
{
for(j=0;j<DIM;j++) printf("%10.5f",AN[i][j]);
printf(" %10.5f\n",a[i]);
}
if(gcpelim(0,AN,a)==1)
{
printf("The rank of overdetermined matrix A is less than COLUMN.\n");
printf("Please use singular value decompsition of matrix A ");
printf("for minimal least squre solution.\n");
printf("Strike any key to exit! \n");
getch(); exit(1);
}
}
extern void mvfitgn(double A[M][N],double y[M],double a[N]);
void main( void)
{
int i;
{
static double a[N];
static double A[M][N]={{1.00,15.58,1.95},{1.00,10.68,1.37},{1.00,15.62,2.33},
{1.00,15.78,1.14},{1.00,13.22,1.85}};
static double y[M]={1.34,1.27,1.56,1.48,1.40};
system("cls");
mvfitgn(A,y,a);
for(i=0;i<N;i++) printf("a(%2d)=%14.8\n",i,a[i]);
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -