Classical Mechanics MatLab problem (oribtal motion)

In summary, the user is trying to solve a differential equation to produce an oscillatory orbit around the sun, but is having trouble.
  • #1
Rhabdovirus
6
0
Hey guys, I've been fighting this problem all weekend with little avail. I only know a little Java, but we have this final project in MatLab, a program I don't really know.

Homework Statement



I need to compute the orbit of a comet using the Runge-Kutte, Euler and midpoint methods. The program should terminate after 1 orbit. I then need to compute eccentricity, a, period and [tex]r_{min}[/tex].

Homework Equations



I'm using the differential equation [tex]\mu \ddot{r}[/tex] = F(r) + l2/[tex]\mu[/tex]2*r2
F(r) is the central force, -GMm/r2 in this case

The Attempt at a Solution



Here's my code so far, I'm having trouble figuring out how to plot it
Code:
%Differential equation:  r'' = F(r)/mu + ((l^2)/((mu^2)*(r^2)))
clear all; help orbit;
%Variables
%Fr = G*Msun*Mcomet/r^2;
%l = Mcomet*v*r;
%Constants
Msun = 2e30;
Mcomet = 2e6;
G = 6.67e-11;
mu = (Msun*Mcomet)/(Msun+Mcomet);
time = 0;

%initial conditions
r0 = 250000; %initial radius from Sun to comet in m
v0 = 8000; %initial tangential velocity of comet in m/s
r = r0; v = v0;
tau = 1000; %timestep in seconds
maxstep = 1000;
for iStep = 1:maxstep
   

  
%Euler Method v_n+1 = (v_n + tau*acc_n)
%				  r_n+1 = (r_n + tau*v_n)

acc = -G*Msun*r./norm(r)^3;
r = r + tau*v;
v = v + tau*acc;
time = time + tau;%Midpoint v_n+1 = v_n + tau*a_n
%			 r_n+1 = r_n + tau*v_n + .5*a_n*tau^2

acc = -G*Msun*r./norm(r)^3;
v = v + tau*acc;
r = r + tau*v + .5*acc*(tau^2);end

Homework Statement


Homework Equations


The Attempt at a Solution

 
Physics news on Phys.org
  • #2
ugh, 75 views and no one knows!

here's an update: I figured out the algorithms, but I'm getting a straight line not the oscillatory one I should be getting.

Code:
%Complete the orbit of a comet around the Sun.  (1) Have the program stop when it has completed one orbit.
%(2) Have the program compute the period (period), eccentricity (sigma), semimajor axis (a) and perihelion distance (rmin). 


%Differential equation:  r'' = F(r)/mu + ((l^2)/((mu^2)*(r^2)))
clear all; help orbit;
%Variables
%Fr = G*Msun*Mcomet/r^2;
%l = Mcomet*v*r;
%Constants
Msun = 2e30;
Mcomet = 2e6;
G = 6.67e-11;
mu = (Msun*Mcomet)/(Msun+Mcomet);

%initial conditions

r(1) = 2500000; %initial radius from Sun to comet in m
v(1) = 8000; %initial tangential velocity of comet in m/s

l = Mcomet*r(1)*v(1);

tau = 1; %timestep in seconds
maxstep = 1000;
acc(1) = (((-1)*G*Msun*Mcomet)/((mu)*(r(1)^2))) + ((l^2)/((mu^2)*(r(1)^3)));
t(1)= tau
for i = 2:maxstep
 
  
%Euler Method v_n+1 = (v_n + tau*acc_n)
%				  r_n+1 = (r_n + tau*v_n)

r(i) = r(i-1) + tau*v(i-1);
acc(i) = (((-1)*G*Msun*Mcomet)/((mu)*(r(i)^2))) + ((l^2)/((mu^2)*(r(i)^3)));
v(i) = v(i-1) + tau*acc(i-1);
t(i) = (i-1)*tau;

plot(t,r);
end
 
  • #3
To get an orbit you need to solve a different diff-eq. Starting from the one you have, you need to change variables and write a second order diff-eq. where the independent variable is the azimuthal angle φ and the dependent variable is 1/r. This is standard stuff, treated in any intermediate level Classical Mechanics textbook.

If you can't find it, I can post the equation for you.
 

1. What is Classical Mechanics?

Classical Mechanics is a branch of physics that deals with the motion of objects under the influence of forces. It is based on Newton's laws of motion and is used to describe the motion of objects in our everyday world.

2. What is MatLab?

MatLab is a high-level programming language and interactive environment that is commonly used in scientific and engineering applications. It allows users to perform complex calculations, create visualizations, and analyze data.

3. How can MatLab be used in orbital motion problems?

MatLab can be used to solve orbital motion problems by using its built-in functions for solving differential equations and performing numerical integration. It also has tools for creating visualizations of orbits and calculating various orbital parameters.

4. Can MatLab handle complex orbital dynamics?

Yes, MatLab can handle complex orbital dynamics by using advanced numerical methods and algorithms. It also has libraries and toolboxes specifically designed for orbital mechanics, making it a powerful tool for solving complex orbital motion problems.

5. What are some common applications of Classical Mechanics and MatLab in orbital motion problems?

Classical Mechanics and MatLab have many applications in orbital motion problems, such as predicting the trajectories of satellites and spacecraft, analyzing the stability of orbits, and simulating the effects of gravitational perturbations on orbital motion.

Similar threads

  • Advanced Physics Homework Help
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
11
Views
784
  • Advanced Physics Homework Help
Replies
7
Views
2K
  • Special and General Relativity
Replies
11
Views
175
  • Introductory Physics Homework Help
Replies
6
Views
738
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Advanced Physics Homework Help
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
14
Views
2K
Back
Top