Re: solve 8x8 matrix



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);
}
}
.



Relevant Pages

  • Re: Wozu noch DOS?
    ... Das meiste davon wird genauso unter MS-DOS 4.0 funktionieren. ... ein Programm mit einer Library linken, wenn man die Library nutzen will. ... Programm sie verwenden will, ist eigentlich nur ein nettes Gimmick. ... Instruktion 'int 10' zu 0xA0000000 springt. ...
    (de.comp.os.msdos)
  • Re: Include files with function prototypes and variable declaration/definition
    ... I would like to write a C programm with multiple include files, ... multiple definition of 'value'. ... extern int value; ... That's a declaration, but not a definition, so it reserves no storage. ...
    (comp.lang.c)
  • Re: Programms memory adress location access?
    ... > TIM wrote: ... > very strange to assign it to an int). ... > Neither of these functions are declared, so this should not compile. ... i just wanted to make programm such ARTMOBNEY if you heard of it... ...
    (comp.lang.cpp)
  • Its right to user CWinThread as mine
    ... I write a thread class derived from CWinThread. ... CListeningThread(LPSTR address, int port); ... virtual BOOL SetSvrInf ... Then I use my class in main programm. ...
    (microsoft.public.vc.mfc)