Page 1 of 1

Gravitational Vector Field

Posted: Sun Oct 14, 2012 10:17 pm
by CommRLock78
Last night I taught myself how to do vector fields in Matlab (I was having trouble visualizing a field from a problem, and realized it was time to figure out how). Here is the earth's vector field in 3D, using m=80kg in F=GMm/r^2

Code: Select all

[x,y,z] = meshgrid(-12E6:2000000:12E6,-12E6:2000000:12E6,-12E6:2000000:12E6);
G=6.67421E-11;
M=5.97E24;
m=80;
F1 = -G*M*m.*x.*(x.^2+y.^2+z.^2).^(-1.5);
F2 = -G*M*m.*y.*(x.^2+y.^2+z.^2).^(-1.5);
F3 = -G*M*m.*z.*(x.^2+y.^2+z.^2).^(-1.5);
quiver3(x,y,z,F1,F2,F3)
xlabel('x')
ylabel('y')
zlabel('z')
Pretty neat to see any vector field you want in 3D :D. (Note that this field could, by looks, be an electric field with a negative point charge at the origin ;)). Don't forget about Octave if you don't have access to Matlab 8)
Edit: In testing this script in QtOctave, I found that for some reason it doesn't display any vectors in the field, just empty space, even though quiver3 appears to be a function, so I don't know why it doesn't work, sorry about that :(.

Edit 2: Here's a picture:
Image