I am trying to model gravity with vector field lines in Matlab. I can kinda do it with a 2D plot, but I cant quite grasp the "scale" field in the(adsbygoogle = window.adsbygoogle || []).push({}); quiverfunction. I then tried to model in 3D vectors and I just made a mess w/ that. Below is my simple 3D and 2D code.

Help w/ this code or if you know a better way to do this would be nice!

non working 3D plot

[X Y Z] = meshgrid(-3:.1:3);

r = sqrt(X.^2 + Y.^2 + Z.^2);

ag = 1./r.^2;

[ax ay az] = gradient(ag);

quiver3(X, Y, Z, ax, ay, az)

Poor 2D plot

M = 1; %Mass of Earth in kg

G = 1; %Gravitational Constant

R = 1; %Radius of Earth in m

[x y] = meshgrid(-3:.75:3);

r = sqrt(x.^2 + y.^2);

ag = G*M./r.^2;

[ax ay] = gradient(ag);

contour(x,y,r,[R R])

colormap cool

hold on

scale = 0;

quiver(x,y,ax,ay,scale)

hold off

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Modeling Gravity with Matlab

**Physics Forums | Science Articles, Homework Help, Discussion**