Gleichungen als for-Schleife
-
Hallo, hoffe jemand kann mir helfen. Wie drücke ich folgendes anders aus (vielleicht mit for-Schleife)???
xo[0]=x[0]; xo[1]=x[1]; xo[2]=x[2]; xo[3]=x[3]; x[0]=(b[0]-((xst[1]*a[0][1])+(xst[2]*a[0][2])+(xst[3]*a[0][3])))/a[0][0]; xst[0]=x[0]; x[1]=(b[1]-((xst[0]*a[1][0])+(xst[2]*a[1][2])+(xst[3]*a[1][3])))/a[1][1]; xst[1]=x[1]; x[2]=(b[2]-((xst[0]*a[2][0])+(xst[1]*a[2][1])+(xst[3]*a[2][3])))/a[2][2]; xst[2]=x[2]; x[3]=(b[3]-((xst[0]*a[3][0])+(xst[1]*a[3][1])+(xst[2]*a[3][2])))/a[3][3]; xst[3]=x[3];
Danke schon mal für eure Antworten.
-
HÄÄÄÄ???
Also das musst du schon vertändlicher ausdrücken.
-
Schau dir die Indizes an, ob die sich sinnvoll in eine Schleife packen lassen. Ansonsten lass es.
-
Meinst du sowas?
.#include<iostream> using namespace std; int main(){ int i=0; //Dekl.der restl.Vars. do{ xo[i]=x[i]; x[i]=(b[i]-((xst[i-i]*a[i+1][i-i])+(xst[i+2]*a[i][i+2-i])+(xst[i+3-i]*a[i][i+3-i])))/a[i][i]; xst[i]=x[i]; if(i==2){ x[i]=(b[i]-((xst[i-i]*a[i+1][i-i])+(xst[i+2]*a[i][i-i+1])+(xst[i+3-i]*a[i][i+3-i])))/a[i][i]; xst[i]=x[i];} if(i==3){ x[i]=(b[i]-((xst[i-i]*a[i+1][i-i])+(xst[i+2]*a[i][i-i+1])+(xst[i-1]*a[i][i-1])))/a[i][i];} i++; }while(i<=3);
[/quote]
-
Cico schrieb:
Meinst du sowas?
.#include<iostream> using namespace std; int main(){ int i=0; //Dekl.der restl.Vars. do{ xo[i]=x[i]; x[i]=(b[i]-((xst[i-i+1]*a[i+1][i-i+1])+(xst[i+2]*a[i][i+2-i])+(xst[i+3-i]*a[i][i+3-i])))/a[i][i]; xst[i]=x[i]; if(i==2){ x[i]=(b[i]-((xst[i-i]*a[i+1][i-i])+(xst[i+2]*a[i][i-i+1])+(xst[i+3-i]*a[i][i+3-i])))/a[i][i]; xst[i]=x[i];} if(i==3){ x[i]=(b[i]-((xst[i-i]*a[i+1][i-i])+(xst[i+2]*a[i][i-i+1])+(xst[i-1]*a[i][i-1])))/a[i][i];} i++; }while(i<=3);
Waren fehler drin...ich denke du weißt wie ichs mein...
-
Hier ne for Schleife...
.#include<iostream> using namespace std; int main(){ int i=0; //Dekl.der restl.Vars. for(i=0;i<=3;i++){ if(i==3){ xo[i]=x[i]; x[i]=(b[i]-((xst[i-i]*a[i+1][i-i])+(xst[i+2]*a[i][i-i+1])+(xst[i-1]*a[i][i-1])))/a[i][i]; xst[i]=x[i];} if(i==2){ xo[i]=x[i]; x[i]=(b[i]-((xst[i-i]*a[i+1][i-i])+(xst[i+2]*a[i][i-i+1])+(xst[i+3-i]*a[i][i+3-i])))/a[i][i]; xst[i]=x[i];} else{ xo[i]=x[i]; x[i]=(b[i]-((xst[i-i+1]*a[i+1][i-i+1])+(xst[i+2]*a[i][i+2-i])+(xst[i+3-i]*a[i][i+3-i])))/a[i][i]; xst[i]=x[i]; } }
Vielleicht kann noch jemand sagen ob das so programmtechnisch korrekt ist...