Output to file not working?

So I've been trying to get a code from Mathematica transfered to C++ to check for something, and for some strange reasons it doesn't run. I've managed to find the problem line, it's the one with writing to the file. I know I probably have a lot of mistakes, but the compiler says no errors, no warnings and of course running crashes. Help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  #include <iostream>
#include <math.h>
#include <fstream>
using namespace std;

int main()
{
int n,m,j,k;
double dt,as,V0,s0,gg,R,d0,aa,bb,dd,dz1daa[1000],dz2daa[1000],dz1dbb[1000],dz2dbb[1000],dz1dcc[1000],dz2dcc[1000],b[3][3],p[3][3];
ofstream outputfile ("outputfile.txt");
n=2;
m=1000;
dt=(2*3.141592)/m;
as=1;
V0=1;
s0=1;
gg=0.01;
R=0.002;
d0=0.0001;
aa=20.877;
bb=1.36701;
for(k=1;k<=989;k++)
{
    b[1][1]=0;
    b[1][2]=0;
    b[1][3]=0;
    b[2][2]=0;
    b[2][3]=0;
    b[3][3]=0;
    for(j=1;j<m;j++)
    {
        dz1daa[j]=as*V0*(4*aa*gg*d0/(R*R)-bb*gg/R)*sin(j*dt);
        dz2daa[j]=(-1)*as*V0*(4*aa*gg*d0/(R*R)-bb*gg/R)*sin(j*dt);
        dz1dbb[j]=as*(2*aa*gg*d0*d0/(R*R)-bb*gg*d0/R+2*gg/(1+sqrt(1-gg*gg)))*sin(j*dt);
        dz2dbb[j]=as*(2*aa*gg*d0*d0/(R*R)-bb*gg*d0/R+2*gg/(1+sqrt(1-gg*gg)))*sin(j*dt);
        dz1dcc[j]=as*V0*(4*aa*d0*d0/(R*R)-bb*d0/R+2/(1+sqrt(1-gg*gg))+2*gg*gg/(sqrt(1-gg*gg)*(1+sqrt(1-gg*gg))*(1+sqrt(1-gg*gg))))*sin(j*dt);
        dz2dcc[j]=(-1)*as*V0*(4*aa*d0*d0/(R*R)-bb*d0/R+2/(1+sqrt(1-gg*gg))+2*gg*gg/(sqrt(1-gg*gg)*(1+sqrt(1-gg*gg))*(1+sqrt(1-gg*gg))))*sin(j*dt);
        b[1][1]=b[1][1]+(dz1daa[j]*dz1daa[j]+dz2daa[j]*dz2daa[j])/m;
        b[1][2]=b[1][2]+(dz1daa[j]*dz1dbb[j]+dz2daa[j]*dz2dbb[j])/m;
        b[1][3]=b[1][3]+(dz1daa[j]*dz1dcc[j]+dz2daa[j]*dz2dcc[j])/m;
        b[2][2]=b[2][2]+(dz1dbb[j]*dz1dbb[j]+dz2dbb[j]*dz2dbb[j])/m;
        b[2][3]=b[2][3]+(dz1dbb[j]*dz1dcc[j]+dz2dbb[j]*dz2dcc[j])/m;
        b[3][3]=b[3][3]+(dz1dcc[j]*dz1dcc[j]+dz2dcc[j]*dz2dcc[j])/m;
    }
    dd=-b[1][3]*b[2][2]*b[1][3]+b[1][2]*b[2][3]*b[1][3]+b[1][3]*b[1][2]*b[2][3]-b[1][1]*b[2][3]*b[2][3]-b[1][2]*b[1][2]*b[3][3]+b[1][1]*b[2][2]*b[3][3];
    p[1][1]=(-b[2][3]*b[2][3]+b[2][2]*b[3][3])/dd;
    p[1][2]=(-b[1][2]*b[3][3]+b[1][3]*b[2][3])/dd;
    p[1][3]=(-b[1][3]*b[2][2]+b[1][2]*b[2][3])/dd;
    p[2][1]=(-b[2][3]*b[2][3]+b[2][2]*b[3][3])/dd;
    p[2][2]=(-b[2][3]*b[2][3]+b[2][2]*b[3][3])/dd;
    p[2][3]=(-b[2][3]*b[2][3]+b[2][2]*b[3][3])/dd;
    p[3][1]=(-b[2][3]*b[2][3]+b[2][2]*b[3][3])/dd;
    p[3][2]=(-b[2][3]*b[2][3]+b[2][2]*b[3][3])/dd;
    p[3][3]=(-b[2][3]*b[2][3]+b[2][2]*b[3][3])/dd;
    outputfile<<gg<<" "<<sqrt(p[1][1])<<" "<<sqrt(p[2][2])<<" "<<sqrt(p[3][3])<<" "<<p[1][2]/sqrt(p[1][1]*p[2][2])<<" "<<p[1][3]/sqrt(p[1][1]*p[3][3])<<" "<<p[2][3]/sqrt(p[3][3]*p[2][2]);
    gg=gg+0.001;
}
outputfile.close();
return 0;
}
Topic archived. No new replies allowed.