c语言a33
1. 姹侰璇瑷缂栫▼瑙d笁鍏冧竴娆℃柟绋嬶纴鍙鐢ㄥ垯锷100鍒嗭紒锛侊紒
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <math.h>
main()
{
int i;
double p[3]={4.5,8.5,10.5},T[3]={72.245116 , 53.377527 , 40.407589},L=12;
double *x;
double c[3][4];
double *ColPivot(double *,int);
for(i=0;i<3;i++)
{c[0][i]=1-p[i]/L;c[1][i]=p[i]/L;c[2][i]=-sin(3.14*p[i]/L);c[i][3]=T[i];}
//12涓鏁颁緷娆′负A11锛孉12锛孉13锛孊1锛孉21锛孉22锛孉23锛孊2锛孉31锛孉32锛孉33锛孊3
x=ColPivot(c[0],3);
//clrscr();
for(i=0;i <=2;i++)
printf( "x[%d]=%f\n ",i,x[i]);
getch();
}
double *ColPivot(double *c,int n)
{
int i,j,t,k;
double *x,p;
x=(double *)malloc(n*sizeof(double));
for(i=0;i <=n-2;i++)
{
k=i;
for(j=i+1;j <=n-1;j++)
if(fabs(*(c+j*(n+1)+i))> (fabs(*(c+k*(n+1)+i)))) k=j;
if(k!=i)
for(j=i;j <=n;j++)
{
p=*(c+i*(n+1)+j);
*(c+i*(n+1)+j)=*(c+k*(n+1)+j);
*(c+k*(n+1)+j)=p;
}
for(j=i+1;j <=n-1;j++)
{
p=(*(c+j*(n+1)+i))/(*(c+i*(n+1)+i));
for(t=i;t <=n;t++)
*(c+j*(n+1)+t)-=p*(*(c+i*(n+1)+t));
}
}
for(i=n-1;i>=0;i--)
{
for(j=n-1;j>=i+1;j--)
(*(c+i*(n+1)+n))-=x[j]*(*(c+i*(n+1)+j));
x[i]=*(c+i*(n+1)+n)/(*(c+i*(n+1)+i));
}
return x;
}
2. c璇瑷缂栫▼锛氢笁鍏冧竴娆℃柟绋嬶纸链濂芥湁娉ㄩ喷锛
娆℃暟杩欎箞浣庯纴鐩存帴濂楃敤Crammer娉曞垯灏卞彲浠ヤ简锛屾渶绠鍗曘
棣栧厛锛屼笁阒惰屽垪寮忕殑瀹氢箟鏄
|a11 a12 a13|
|a21 a22 a23|
|a31 a32 a33|
= a11*a22*a33 + a12*a23*a31 + a21*a32*a13 - a31*a22*a13 - a21*a12*a33 - a32*a23*a11
璁版柟绋嬩负
a11 * x + a12 * y + a13 * z = b1
a21 * x + a22 * y + a23 * z = b2
a31 * x + a32 * y + a33 * z = b3
骞惰
D =
|a11 a12 a13|
|a21 a22 a23|
|a31 a32 a33|
Dx =
|b1 a12 a13|
|b2 a22 a23|
|b3 a32 a33|
Dy =
|a11 b1 a13|
|a21 b2 a23|
|a31 b3 a33|
Dz =
|a11 a12 b1|
|a21 a22 b2|
|a31 a32 b3|
鍒
褰揇涓崭负0镞讹纴鏂圭▼缁勬湁鍞涓瑙o细
x = Dx / D
y = Dy / D
z = Dz / D