Data from 2nd order ode mathematica

Click For Summary

Discussion Overview

The discussion revolves around extracting time data from a system of second-order ordinary differential equations (ODEs) in Mathematica, specifically in the context of simulating the 2-body problem. Participants explore methods for visualizing and retrieving numerical data from the simulation.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Exploratory

Main Points Raised

  • One participant asks how to extract time data from a system of second-order ODEs in Mathematica.
  • Another participant requests the ODEs and the Mathematica code used so far to better understand the context.
  • A participant provides a detailed Mathematica code snippet for simulating the 2-body problem, including parameters for mass, initial position, and velocity.
  • Suggestions are made to modify the plotting commands to include points along the trajectory and label them with corresponding time values.
  • An alternative approach is proposed to generate a table of numerical results that includes time and position data, which can be formatted for clarity.

Areas of Agreement / Disagreement

There is no explicit consensus on the best method to extract time data, as participants propose different approaches and modifications without resolving which is superior.

Contextual Notes

The discussion includes various assumptions about the simulation parameters and the desired output format, which may affect the applicability of the proposed solutions.

Dustinsfl
Messages
2,217
Reaction score
5
How can I extract time data from a system 2nd order ODEs in Mathematica?
 
Physics news on Phys.org
Can you post the ODE's and your Mathematica code so far?
 
Ackbach said:
Can you post the ODE's and your Mathematica code so far?

Code:
Numerical Simulation of the 2-Body Problem

ClearAll["Global`*"];

We begin with of the the necessary data for this problem...

M = 5974*10^21; (* mass of Earth, kg *)

m = 1000; (* mass of  spacecraft , kg *)

\[Mu] = 3.986*10^5; (* gravitaional parameter, based on km units of length, \
km/s for velocity *)

Rearth = 6378; (* radius of the Earth, km *)Simulation Inputs

r0 = {3950.55, 43197.9, 0};(* initial position vector, km *)
v0 = {3.3809, -7.25046, 0}; (* initial velocity vector, km *)
Days = 1/10; (* elapsed time of simulation days *)

\[CapitalDelta]t = Days*24*3600;(* convert elapsed days to seconds *)

s = NDSolve[
   {
    x1''[t] == -(\[Mu]/(Sqrt[x1[t]^2 + x2[t]^2 + x3[t]^2])^3)*x1[t],
    x2''[t] ==  -(\[Mu]/(Sqrt[x1[t]^2 + x2[t]^2 + x3[t]^2])^3)*x2[t],
    x3''[t] ==  -(\[Mu]/(Sqrt[x1[t]^2 + x2[t]^2 + x3[t]^2])^3)*x3[t],
    
    x1[0] == r0[[1]], (* intial x-position of satellite *)
    
    x2[0] == r0[[2]],(* intial y-position of satellite *)
    
    x3[0] == r0[[3]],(* intial y-position of satellite *)
    
    x1'[0] == v0[[1]],(* intial vx-rel of satellite *)
    
    x2'[0] == v0[[2]],(* intial vy-rel of satellite *)
    
    x3'[0] == v0[[3]](* intial vy-rel of satellite *)
    
    },
   {x1, x2, x3},
   {t, 0, \[CapitalDelta]t} 
   ];

Plot of the Trajectory Relative to Earth

g1 = ParametricPlot3D[
   Evaluate[{x1[t], x2[t], x3[t]} /. s], {t, 0, \[CapitalDelta]t},  
   PlotStyle -> {Red, Thick}];
g2 = Graphics3D[{Blue, Opacity[0.6], Sphere[{0, 0, 0}, Rearth]}];Show[g2, g1, Boxed -> False]
 
I'm not certain exactly what you are expecting when you "extract time data", but perhaps something in this will help.What if you replaceShow[g2, g1, Boxed -> False]

with

g3 = Graphics3D[Table[Point[{x1[t], x2[t], x3[t]} /. s[[1]]], {t, 0, Δt, Δt/10}]];
g4 = Graphics3D[Table[Text[ToString[t], {x1[t], x2[t], x3[t]} /. s[[1]], {1, 0}], {t, 0, Δt, Δt/10}]];
Show[g2, g1, g3, g4, Boxed -> False]That will place points along your path and label each point with the associated value of t. You can adjust the step size and the label position next to each point as needed.

If that doesn't provide you with the necessary level of detail then you might try using

Table[{t,x1[t],x2[t],x3[t]}/.s[[1]], {t,0,Δt,Δt/10}]//TableForm

with appropriate step size to give you the numerical results to go along with your plot.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K