Advertisement
ksoltan

gravity_force_func.m

Nov 30th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.69 KB | None | 0 0
  1. %% Returns the force gravity on m1 due to m2.
  2. function res = gravity_force_func(point1, m1, point2, m2)
  3.     % Returns force exherted by m1 on m2
  4.     res = force(point2, point1);
  5.    
  6.     %% Returns force of gravity directed in direction from from to to.
  7.     function res = force(from, to)
  8.        G = 6.67 * 1e-11; % N m^2 / kg^2
  9.        R = to - from; % how far from "from" is "to"? This is the vector to it
  10.        mag_r = norm(R); % magnitude of the direction vector
  11.        dir_r = (R) / mag_r; % unit vector in direction from to to.
  12.        Fg = G * m1 * m2 / mag_r^2; % magnitude of force of gravity
  13.        res = Fg * dir_r; % force of gravity in direction from from to to
  14.     end
  15.    
  16. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement