solving odes and plotting

Ive been trying to solve these equations -
d2x dt2 = 2 dy dt + x− M(x + E) Re3 − E(x−M) Rm3
d2y dt2 = −2 dx dt + y− My Re3 − Ey Rm3
z1 = x, z2 = dx dt , z3 = y, and z4 = dy dt
and plot the solution to get a graph looking something like this:
though my plot keeps coming ether empty with the moon and earth or having three separate solution line
how can i get it to plot the potions x,y like in the above picture

 Accepted Answer

Steven Lord
Steven Lord on 29 Nov 2017
Use the OutputFcn and OutputSel options. If you look at the "Restricted Three Body Problem" example on this documentation page you'll see that the pictures it creates bear some similarity to the picture you showed. If you look at the code for that example by editing the orbitode function, you'll see it uses odephas2 as the OutputFcn. The way you've formulated your problem, with z1 = x and z3 = y, means that you'll need to use the OutputSel option to tell the ODE solver to pass components 1 and 3 of the solution into the OutputFcn.
Both these options are described on the documentation page for the odeset function.

More Answers (0)

Tags

Asked:

del
on 29 Nov 2017

Answered:

on 29 Nov 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!