My graph is blank
Show older comments
I am trying to calculate and graph the variations of g with height for the different planets I have in my variables, but once i hit run i get the graph, but no line being plotted. This is the code
clc;
load project_1.mat
g= @(x,M)((G*M)./(x.^2));
dist = vpa(linspace(1,10^8,1000));
figure
hold on
g_Earth = g(dist, Mass_Earth);
g_Jupiter = g(dist, Mass_Jupiter);
g_Mars = g(dist, Mass_Mars);
g_Moon = g(dist, Mass_Moon);
plot(dist, g_Earth)
plot(dist, g_Jupiter)
plot(dist, g_Mars)
plot(dist, g_Moon)
xlabel('Height from surface of planet');
ylabel('Acceleration due to gravity');
title('g vs Height from surface of planets')
legend({'Earth','Jupiter','Mars','Moon'})
savefig('task3_graph.fig')
3 Comments
Torsten
on 13 Sep 2022
G is undefined.
Walter Roberson
on 13 Sep 2022
hold on freezes the axes limits. After you plot
xlim auto; ylim auto
Bryan
on 13 Sep 2022
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!