# [SOLVED]following on to ODE thread 2nd order to 1st

#### dwsmith

##### Well-known member
I am getting this error in Mathematica from the code below:
Computed derivatives do not have dimensionality consistent with the initial conditions

Code:
ClearAll["Global*"]
\[Mu] = 398600;
s = NDSolve[{x1'[t] == x2[t],
y1'[t] == y2[t],
z1'[t] == z2[t],
x2'[t] == -\[Mu]*x1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^{3/2},
y2'[t] == -\[Mu]*y1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^{3/2},
z2'[t] == -\[Mu]*z1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^{3/2},
x1[0] == -201000*Sqrt[3],
y1[0] == 201000,
z1[0] == 0,
x2[0] == -2.04119,
y2[0] == 0.898024,
z2[0] == 0}, {x, y, z}, {t, 0, 50}];

#### Ackbach

##### Indicium Physicus
Staff member
I don't have MMA handy to use, but a few things I see you might change:

Code:
ClearAll["Global*"]
\[Mu] = 398600;
s = NDSolve[{x1'[t] == x2[t],
y1'[t] == y2[t],
z1'[t] == z2[t],
x2'[t] == -\[Mu]*x1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
y2'[t] == -\[Mu]*y1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
z2'[t] == -\[Mu]*z1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
x1[0] == -201000*Sqrt[3],
y1[0] == 201000,
z1[0] == 0,
x2[0] == -2.04119,
y2[0] == 0.898024,
z2[0] == 0}, {x1,x2, y1,y2, z1,z2}, {t, 0, 50}];
So I changed the curly braces to parentheses, as well as added the correct dependent variables in the list at the bottom. Does that work?

#### dwsmith

##### Well-known member
I don't have MMA handy to use, but a few things I see you might change:

Code:
ClearAll["Global*"]
\[Mu] = 398600;
s = NDSolve[{x1'[t] == x2[t],
y1'[t] == y2[t],
z1'[t] == z2[t],
x2'[t] == -\[Mu]*x1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
y2'[t] == -\[Mu]*y1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
z2'[t] == -\[Mu]*z1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
x1[0] == -201000*Sqrt[3],
y1[0] == 201000,
z1[0] == 0,
x2[0] == -2.04119,
y2[0] == 0.898024,
z2[0] == 0}, {x1,x2, y1,y2, z1,z2}, {t, 0, 50}];
So I changed the curly braces to parentheses, as well as added the correct dependent variables in the list at the bottom. Does that work?
It fixed the error but nothing plots:
Code:
ParametricPlot3D[
Evaluate[{x1[t], y1[t], z1[t], x2[t], y2[t], z2[t]} /. s], {t, 0,
50}, Boxed -> False, PlotRange -> All, PlotStyle -> {Red}]

#### Ackbach

##### Indicium Physicus
Staff member
Try something simpler: a 1-D plot of just x2[t]/.s:

Plot[x1[t]/.s,{t,0,50}]

Does that plot?

#### dwsmith

##### Well-known member
Try something simpler: a 1-D plot of just x2[t]/.s:

Plot[x1[t]/.s,{t,0,50}]

Does that plot?
I am working on making a little setup that evaluates trajectories for 2 body and restricted 3 body problem. That is why I wanted to change the 2nd order equation of motion for planetary bodies in two 1st order equations.

#### Ackbach

##### Indicium Physicus
Staff member
Well, I understand that you want to plot a parametric 3D plot, but I'm just trying to debug your code. Start small, and build up to the big plot.

#### dwsmith

##### Well-known member
Well, I understand that you want to plot a parametric 3D plot, but I'm just trying to debug your code. Start small, and build up to the big plot.
I have done many of smaller plots. You can view my notes in the ODE section to see. Everything seems correct so I don't see the issue.

That smaller plot wont run.

#### Ackbach

##### Indicium Physicus
Staff member
I'm a little unclear what the \[Mu] notation means. Why not try this:

ClearAll["Global*"]
Mu = 398600;
s = NDSolve[{x1'[t] == x2[t],
y1'[t] == y2[t],
z1'[t] == z2[t],
x2'[t] == -Mu*x1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
y2'[t] == -Mu*y1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
z2'[t] == -Mu*z1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
x1[0] == -201000*Sqrt[3],
y1[0] == 201000,
z1[0] == 0,
x2[0] == -2.04119,
y2[0] == 0.898024,
z2[0] == 0}, {x1,x2,y1,y2,z1,z2}, {t, 0, 50}];

Does a small plot work on this?

#### dwsmith

##### Well-known member
I'm a little unclear what the \[Mu] notation means. Why not try this:

ClearAll["Global`*"]
Mu = 398600;
s = NDSolve[{x1'[t] == x2[t],
y1'[t] == y2[t],
z1'[t] == z2[t],
x2'[t] == -Mu*x1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
y2'[t] == -Mu*y1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
z2'[t] == -Mu*z1[t]/(x1[t]^2 + y1[t]^2 + z1[t]^2)^(3/2),
x1[0] == -201000*Sqrt[3],
y1[0] == 201000,
z1[0] == 0,
x2[0] == -2.04119,
y2[0] == 0.898024,
z2[0] == 0}, {x1,x2,y1,y2,z1,z2}, {t, 0, 50}];

Does a small plot work on this?
\[Mu] = $\mu$ symbol in Mathematica

#### Ackbach

##### Indicium Physicus
Staff member
Well, my only advice is to start stripping things out of your model (like dimensions) until you get something that works. Then start adding things back in.

#### dwsmith

##### Well-known member
Well, my only advice is to start stripping things out of your model (like dimensions) until you get something that works. Then start adding things back in.
The problem was t. Since I am dealing with space flight, t of 250 is only 250 seconds. Taking t > 1million yields results.

Last edited: