How can I accurately model gravity using vector fields in Matlab?

Click For Summary
SUMMARY

This discussion focuses on modeling gravity using vector fields in Matlab, specifically utilizing the quiver function for both 2D and 3D plots. The user struggles with the "scale" parameter in the quiver function and encounters issues when attempting to visualize 3D vectors. The provided code snippets illustrate attempts to create gravitational field representations, but they require refinement for accurate visualization.

PREREQUISITES
  • Understanding of vector fields in physics
  • Familiarity with Matlab programming
  • Knowledge of the quiver and quiver3 functions in Matlab
  • Basic concepts of gravitational force and its mathematical representation
NEXT STEPS
  • Explore Matlab's quiver function documentation for detailed parameter explanations
  • Learn about 3D plotting techniques in Matlab, focusing on quiver3
  • Research gradient calculation methods in Matlab for vector field generation
  • Investigate alternative visualization tools for vector fields, such as MATLAB's streamlines
USEFUL FOR

This discussion is beneficial for physicists, engineers, and Matlab users interested in accurately modeling gravitational fields and enhancing their skills in vector field visualization.

Dirty D
Messages
6
Reaction score
0
I am trying to model gravity with vector field lines in Matlab. I can kinda do it with a 2D plot, but I can't quite grasp the "scale" field in the quiver function. 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
 
Last edited:
Physics news on Phys.org
Prehaps you could post an image file of some sort. I cannot open your .m file and will not aprove it without doing so.
 
is this better?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 16 ·
Replies
16
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K