16 views (last 30 days)

clc;

clear all;

close all;

format long g;

G=6.6743015*10^-11;

Density=5.510;

M= (4*pi*G*Density)*10^6/3;

R=[10 20 50 100 6370];

%% for the calculation for the gravitational potential

for i =1:length(R)

Gravitational_Potential(:,i) = (M*R(:,i));

i=i+1;

end

figure()

plot(R,Gravitational_Potential);

ylabel('Gravitational Potential');

xlabel('Radius of the Sphere');

title('Gravitational potential vs Radius ');

grid on

I have to plot as curve plot as attached

Hint : - consider you have a function y = x^2. And now you have points x=1,2,4,8, from this you can get the corresponding y values: y=1^2,2^2,4^2,8^2. How do you visualize these values?

Now you have the same with a function V=GM/R, and R=10k,… you got V for all these values, you can visualize your results the same way you did above.

Ameer Hamza
on 6 May 2020

Edited: Ameer Hamza
on 6 May 2020

You are using wrong values of constants and wrong formula for Gravitational potential. Try this code

clc;

clear all;

close all;

format long g;

G=6.6743015e-11;

Density=5510;

R = 6.4e6; % radius of earth

M = 4*pi*R^3*Density/3;

r = linspace(R, 15*R);

%% for the calculation for the gravitational potential

Gravitational_Potential = zeros(size(r));

for i =1:length(r)

Gravitational_Potential(i) = -G*M/r(i);

end

figure()

ax = axes();

plot(r, Gravitational_Potential);

ax.XLim(2) = max(r);

ylabel('Gravitational Potential');

xlabel('Radius of the Sphere');

title('Gravitational potential vs Radius ');

grid on

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 5 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_842813

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_842813

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_847716

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_847716

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_847913

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_847913

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_848829

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_848829

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_848850

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/523541-how-to-plot-the-gravitational-potential-vs-radius-of-earth-plot#comment_848850

Sign in to comment.