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