- #1
Leonardo Machado
- 57
- 2
Hello, thanks for your interest in may help me, i appreciate it, really.
My question is, I've wrote this code to solve an physical EDO system. But for some reason it copies the element k[1][3] at k[2][3].
After i call the initials elements the code becomes:
Help me please, i have no more ideas !
My question is, I've wrote this code to solve an physical EDO system. But for some reason it copies the element k[1][3] at k[2][3].
After i call the initials elements the code becomes:
Code:
for ( int n=1 ; n<=1; n++ ){
pe= dpe*(n-1);
cout << endl << endl << "pe= " << pe << endl ;
file << endl << "pe= " << pe << " ";
for ( int l=1 ; l<=4 ; l++){
for ( int j=1 ; j<=i ; j++){
if ( l==1){
px[j][l]= p[j];
pex[j][l]= pe;
}
if ( l==2){
px[j][l]= p[j]+ dpe*k[j][1]/2;
pex[j][l]= pe+ dpe/2;
}
if ( l==3){
px[j][l]= p[j]+ dpe*k[j][2]/2;
pex[j][l]= pe+ dpe/2;
}
if ( l==4){
px[j][l]= p[j]+ dpe*k[j][3];
pex[j][l]= pe+ dpe;
}
cout << "px" << j << "." << l << "= " << px[j][l] << " " ;
}
for ( int j=1; j<=i; j++){
if ( j==1){
f[j]=px[3][l];
}
if ( j==2){
f[j]= px[4][l];
}
if (j==3){
f[j]= (-GM) * px[1][l] / pow ( sqrt ( pow ( px[1][l], 2) + pow ( px[2][l], 2)), 3);
}
if (j==4){
f[j]= (-GM) * px[2][l] / pow ( sqrt ( pow ( px[1][l], 2) + pow ( px[2][l], 2)), 3);
}
k[j][l]= f[j];
}
for ( int j=1; j<=i; j++){
cout << "k" << j << "." << l << "= " << k[j][l] << " " ;
}
cout << endl << endl;
}
for ( int j=1 ; j<=i ; j++){
file << p[j] << " ";
cout << "p." << j << "= " << p[j] << " ";
p[j]=p[j]+ dpe*(k[j][1]+k[j][4]+ 2*(k[j][2]+k[j][3]))/6;
}
}
}