[MATLAB] Modeling gravity using polar coordinates Argh

In summary, the author's simulation shows that gravity does not affect the orbital velocity of a rocket, but for it to orbit, the rocket must have a cyclic, non-zero height. Something is wrong here, and the author can't tell what it is.
  • #1
ellipsis
158
24
I've been using MATLAB (ode45) to simulate the mechanics of a rocket under the forces of gravity, drag, and internal thrust.y I've recently refactored my simulation to include 2d space, orientation of the rocket, etc. (So I can try to make it orbit, finding optimal ascent profiles, etc)

Because I want to retain the simplicity of my 1d model, I've attempted to use polar coordinates for defining the rockets position, velocity, and acceleration. I've implemented it, but when I run the simulation and plot height vs theta... I get a disturbing picture.

Gravity does not affect the orbital velocity in any way. It always accelerates the height of the rocket downward. And yet for it to orbit, it needs to have a cyclic, non-zero height. Something is very wrong here, and I can't tell what it is.

The line defining gravitational acceleration is as follows. I define it as a vector, with the first component being orbital acceleration (how much theta's rate of change changes due to gravity), and the second component being height's acceleration. (height is y, here)
Code:
grav = [0; -S/(R+y)^2];

Since S (the standard gravitation parameter) is positive, the acceleration of height will always be negative. The height of the rocket must inevitably go to zero. My intuition of gravity no longer makes sense.

This is bothering me on a visceral level. I can't tell what I'm doing wrong. I now suspect the Earth will fall into Sol in the next few hours.
 
Physics news on Phys.org
  • #2
It would help if you posted the whole MATLAB script as some folks have MATLAB and could run it to see what's happening.
 
  • #3
All right, I will post the whole thing. It's large though. There's four files, p_step.m, simul.m, eventy.m, and designer.m

p_step.m is the function ode45 calls, and is basically a system of nonlinear differential equations.
simul.m is the main script which calls ode45 and plots the data.
eventy.m defines events (out_of_fuel, and ground_collision)
designer.m specifies rocket properties (thrust, efficiency, etc)

p_step.m:
Code:
function dx = p_step(~, Z)

  global T II IF;
  global TH;
  

  S = 3.5316E12;
  R = 6E5;
  D = 9.784758844E-4;
  H = 5E3;
  G = 9.82;
  
  x = Z(1);
  y = Z(2);
  TH = y*3.14/200000;
  
  vx = Z(3);
  vy = Z(4);
  th = Z(5);
  m = Z(6);
  
  atm = exp(-y/H);
  
  grav = [0; -S/(R+y)^2];
  drag = -D*atm*[vx; vy].^2;
  thrust = T/m*[sin(TH); cos(TH)];
  
  a = thrust + drag + grav;
  ax = a(1);
  ay = a(2);
  
  dm = T/(((IF-II)*atm-IF)*G);
  dth = 0;
  
  dx = [vx; vy; ax; ay; dth; dm];
  
end

simul.m:
Code:
  global T II IF ME MF;

  type = 8;

  T = engine_thrusts(type);
  II = engine_atm_isps(type);
  IF = engine_vac_isps(type);
  ME = engine_masses(type);
  
  G = 9.82;
  R = 1.5;
  
  MI = T/(G*R);
  MF = (MI+7*ME)/8;
  
  
  opt = odeset('Events',@eventy);
  
  [t,y,~,ey,ei] = ode45(@p_step,[0 1000],[0, 0, 0, 0, 0, MI], opt); 
  plot(y(:,1), y(:,2));
  
  if (numel(ei)~=0)
  switch ei(1)
  case 1
  max_dv = ey(3);
  case 2
  max_dv = -1;
  end
  else
  fprintf('Flight timed out\n');
  max_dv = 0;
  end
  
  fprintf('max-velocity:\t%.2f\n',max_dv);

eventy.m:
Code:
function [zero, terminal, negative] = eventy(~,x)

  global MF;
  
  zero = [x(6) - MF; sign(x(2))+1];
  terminal = [1; 1];
  negative = [0; 0];
  
end

designer.m:
Code:
global engine_names engine_thrusts engine_masses engine_atm_isps engine_vac_isps;

engine_names = ['LV-1 Liquid Fuel Engine'... % 1
  'Rockomax 48-7S'... % 2
  'LV-909 Liquid Fuel Engine'... % 3
  'LV-N Atomic Rocket Motor'... % 4
  'R.A.P.I.E.R. Engine'... % 5
  'Toroidal Aerospike Rocket'... % 6
  'LV-T45 Liquid Fuel Engine'... % 7
  'LV-T30 Liquid Fuel Engine'... % 8
  'Rockomax "Poodle" Liquid Engine'... % 9
  'Rockomax "Skipper" Liquid Engine'... % 10
  'Rockomax "Mainsail" Liquid Engine'... % 11
  'Kerbodyne KR-2L Advanced Engine'... % 12
  'S3 KS-25x4 Engine Cluster']; % 13

engine_thrusts = [4 30 50 60 175 175 200 215 220 650 1500 2500 3200];

engine_masses = [.03 .1 .5 2.25 1.2 1.5 1.5 1.25 2 3 6 6.5 9.75];

engine_atm_isps = [220 300 300 220 320 388 320 320 270 320 320 280 320];

engine_vac_isps = [290 350 390 800 360 390 370 370 390 370 360 380 360];

fuel_names = ['Kerbodyne S3-14400 Tank'...
  'Kerbodyne S3-7200 Tank'...
  'Rockomax Jumbo-64 Fuel Tank'...
  'Kerbodyne S3-3600 Tank'...
  'Rockomax X200-32 Fuel Tank'...
  'Rockomax X200-16 Fuel Tank'...
  'FL-T800 Fuel Tank'...
  'Rockomax X200-8 Fuel Tank'...
  'FL-T400 Fuel Tank'...
  'FL-T200 Fuel Tank'...
  'FL-T100 Fuel Tank'...
  'ROUND-8 Toroidal Fuel Tank'...
  'Oscar-B Fuel Tank'];

fuel_full_mass = [82 41 36 20.5 18 9 4.5 4.5 2.25 1.125 0.5625 0.136 0.078675];

fuel_empty_mass = [10 5 4 2.5 2 1 0.5 0.5 0.25 0.125 0.0625 0.025 0.015];

I don't think the problem is in the MATLAB code, though. I think it's a conceptual problem I'm having. If acceleration due to gravity is perpendicular (has no affect on) orbital velocity, why do orbiting objects get faster near the gravitational body?
 
  • #4
Thats large? Medium for programming is 10K lines and large is 100K lines...
 
  • #5
jedishrfu said:
Thats large? Medium for programming is 10K lines and large is 100K lines...

My program is plenty large! D:<

Can you help me understand orbits jedish, or are you satisfied with insulting the length and girth of my program? ;)
 

1. What are polar coordinates in MATLAB?

Polar coordinates in MATLAB refer to a coordinate system that uses angles and distances from a central point to describe the location of a point in a two-dimensional space. It is represented by the notation (r, θ), where r is the distance from the origin and θ is the angle from a fixed reference direction.

2. How can I model gravity using polar coordinates in MATLAB?

To model gravity using polar coordinates in MATLAB, you can use the equations of motion to calculate the gravitational force between two objects based on their masses and distances. You can then use polar coordinates to determine the direction of the force and its components along the radial and tangential directions.

3. What are the advantages of using polar coordinates in gravity modeling?

Using polar coordinates in gravity modeling can simplify the equations and make them easier to solve, especially for systems with symmetric shapes. It also allows for a more intuitive understanding of the direction and magnitude of the gravitational force.

4. Are there any limitations to modeling gravity using polar coordinates in MATLAB?

One limitation of using polar coordinates in gravity modeling is that it is only suitable for two-dimensional systems. Three-dimensional systems would require spherical coordinates for a more accurate representation. Additionally, polar coordinates may not be the most efficient method for complex or irregularly shaped systems.

5. Can I simulate the effects of gravity on multiple objects using polar coordinates in MATLAB?

Yes, you can use polar coordinates in MATLAB to model the gravitational interactions between multiple objects. By calculating the forces between each pair of objects and summing them up, you can simulate the motion of a system of objects under the influence of gravity.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Classical Physics
Replies
7
Views
827
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
Replies
1
Views
619
  • Special and General Relativity
Replies
8
Views
903
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • Beyond the Standard Models
Replies
9
Views
480
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top