Following on to ODE thread 2nd order to 1st

In summary, the conversation discussed a Mathematica error related to dimensionality of computed derivatives and the initial conditions. Various suggestions were made to fix the error, such as changing curly braces to parentheses, adding the correct dependent variables in the list, and stripping out unnecessary elements in the model. Ultimately, the issue was resolved by adjusting the value of t to a larger number.
  • #1
Dustinsfl
2,281
5
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}];
 
Physics news on Phys.org
  • #2
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?
 
  • #3
Ackbach said:
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}]
 
  • #4
Try something simpler: a 1-D plot of just x2[t]/.s:

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

Does that plot?
 
  • #5
Ackbach said:
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.
 
  • #6
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.
 
  • #7
Ackbach said:
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 won't run.
 
  • #8
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?
 
  • #9
Ackbach said:
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
 
  • #10
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.
 
  • #11
Ackbach said:
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:

Related to Following on to ODE thread 2nd order to 1st

1. What is the purpose of converting a 2nd order ODE to a 1st order ODE?

The purpose of converting a 2nd order ODE to a 1st order ODE is to simplify the problem and make it easier to solve. By introducing a new variable, the 2nd order ODE can be rewritten as a system of two 1st order ODEs, which can then be solved using numerical methods.

2. How do you convert a 2nd order ODE to a 1st order ODE?

To convert a 2nd order ODE to a 1st order ODE, we introduce a new variable, typically denoted as y, and rewrite the equation as a system of two 1st order ODEs. The first equation will be y' = f(x,y,z), where z is the derivative of the original function. The second equation will be z' = g(x,y,z), where g(x,y,z) is the original function.

3. What are the advantages of converting a 2nd order ODE to a 1st order ODE?

Converting a 2nd order ODE to a 1st order ODE has several advantages. It simplifies the problem and makes it easier to solve using numerical methods. It also allows us to generalize the solution to a wider range of problems. Furthermore, it can help us to identify patterns and relationships between different variables in the system.

4. Are there any limitations to converting a 2nd order ODE to a 1st order ODE?

While converting a 2nd order ODE to a 1st order ODE has many benefits, there are also some limitations. In some cases, it may not be possible to find a suitable new variable to convert the equation. Additionally, the process of converting the equation may introduce errors or inaccuracies in the solution, so it is important to carefully check the results.

5. Can a 2nd order ODE always be converted to a 1st order ODE?

No, not all 2nd order ODEs can be converted to 1st order ODEs. Some equations may not have a suitable new variable that can be introduced to rewrite the equation as a system of two 1st order ODEs. In these cases, alternative methods or approaches may be needed to solve the problem.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
908
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • Classical Physics
Replies
2
Views
1K
  • Introductory Physics Homework Help
Replies
4
Views
897
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • Calculus and Beyond Homework Help
Replies
11
Views
1K
Back
Top