Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Returns the force gravity on m1 due to m2.
- function res = gravity_force_func(point1, m1, point2, m2)
- % Returns force exherted by m1 on m2
- res = force(point2, point1);
- %% Returns force of gravity directed in direction from from to to.
- function res = force(from, to)
- G = 6.67 * 1e-11; % N m^2 / kg^2
- R = to - from; % how far from "from" is "to"? This is the vector to it
- mag_r = norm(R); % magnitude of the direction vector
- dir_r = (R) / mag_r; % unit vector in direction from to to.
- Fg = G * m1 * m2 / mag_r^2; % magnitude of force of gravity
- res = Fg * dir_r; % force of gravity in direction from from to to
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement