Mostrar comentarios más antiguos
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 comentarios
Torsten
el 13 de Sept. de 2022
G is undefined.
Walter Roberson
el 13 de Sept. de 2022
hold on freezes the axes limits. After you plot
xlim auto; ylim auto
Bryan
el 13 de Sept. de 2022
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
