Afficher commentaires plus anciens
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 commentaires
Torsten
le 13 Sep 2022
G is undefined.
Walter Roberson
le 13 Sep 2022
hold on freezes the axes limits. After you plot
xlim auto; ylim auto
Bryan
le 13 Sep 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
