Re: solve 8x8 matrix
- From: Jean-Claude Arbaut <jcarbaut@xxxxxxxxxxx>
- Date: Mon, 12 Jun 2006 14:18:29 +0200
roger.merz@xxxxxxxxx wrote:
Hi NG
I have to solve the following b=Ax system:
A = [ 0 0 1 0 0 0 0 0;
511 0 1 0 0 0 -308644 0;
0 255 1 0 0 0 0 -22950;
511 255 1 0 0 0 -272363 -135915;
0 0 0 0 0 1 0 0;
0 0 0 511 0 1 -133371 0;
0 0 0 0 255 1 0 -79050;
0 0 0 511 255 1 -228417 -113985];
b = [ 126;
604;
90;
533;
116;
261;
310;
447];
x=A\b
I programm in C++. The variables not equal 0 or 1 are dynamic. Solving
the system with the Gauss Jordan algorithm is instable,
No, it's not unstable...
With a simple Gauss pivoting program, the solution is
(computed with Turbo C 2.01, source at the end):
9.19369974535789392e-01
-1.14059861122196501e-01
1.26000000000000000e+02
2.76821492962159521e-01
8.54185968552957142e-01
1.16000000000000000e+02
-2.65741210333318317e-05
3.01295660733764340e-04
so I tried
Gauss Seidel but without success. Does anyone have a idea, how I can
get the x with tollerance less than 0.01%?
Actually, the system is so "friendly" that computed values are exact
(up to machine accuracy, when compared with Carlos' values).
Many Thanks Roger Merz
#include <stdio.h>
#include <math.h>
#define a(i,j) a[n*(i)+(j)]
#define swap(x,y,d) {d=x;x=y;y=d;}
void gauss(int,double*,double*);
int main() {
int n=8,i;
double a[]={
0,0,1,0,0,0,0,0,
511, 0, 1, 0, 0, 0,-308644, 0,
0, 255, 1, 0, 0, 0, 0,-22950,
511,255,1,0,0,0,-272363,-135915,
0,0,0,0,0,1,0,0,
0,0,0,511,0,1,-133371,0,
0,0,0,0,255,1,0,-79050,
0,0,0,511,255,1,-228417,-113985
};
double b[]={126,604,90,533,116,261,310,447};
gauss(n,a,b);
for(i=0;i<n;i++) printf("%.18le\n",b[i]);
return 0;
}
void gauss(int n,double *a,double *b) {
int i,j,k;
double z;
for(i=0;i<n-1;i++) {
k=i; z=fabs(a(i,i));
for(j=i+1;j<n;j++) {
if(fabs(a(j,i))>z) {
k=j;
z=fabs(a(j,i));
}
}
if(k!=i) {
for(j=i;j<n;j++) swap(a(i,j),a(k,j),z);
swap(b[i],b[k],z);
}
for(j=i+1;j<n;j++) {
z=a(j,i)/a(i,i);
for(k=i+1;k<n;k++) a(j,k)-=z*a(i,k);
b[j]-=z*b[i];
}
}
for(i=n-1;i>=0;i--) {
for(j=i+1;j<n;j++) b[i]-=b[j]*a(i,j);
b[i]/=a(i,i);
}
}
.
- Follow-Ups:
- Re: solve 8x8 matrix
- From: roger.merz@xxxxxxxxx
- Re: solve 8x8 matrix
- References:
- solve 8x8 matrix
- From: roger.merz@xxxxxxxxx
- solve 8x8 matrix
- Prev by Date: Re: solve 8x8 matrix
- Next by Date: Re: New mathematics/physical sciences positions at http://jobs.phds.org, June 12, 2006
- Previous by thread: Re: solve 8x8 matrix
- Next by thread: Re: solve 8x8 matrix
- Index(es):
Relevant Pages
|