Plotting end points from different arrays
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
This program has been used to plot graphs of various variables against time to see how they change. The variable Qe is changed by repeatedly decreasing by 0.1 and then the plots are put together on one graph. I was wanting to plot the end points of these variables (a, e, de, da) against Qe however I have been unable to do so. Any help is appreciated.
format long
g = 36;
M = 10000002;
a = zeros(M,1);
e = zeros(M,1);
da = zeros(M-1,1);
de = zeros(M-1,1);
T = [0:10000000];
e(1) = 0.0549;
a(1) = 0.3844e9;
for m = 0:10000000
de(m+1) = -(4.04562756e41 + ((2.75561858e40)/g)) * ((a(m+1))^(-13/2)) * e(m+1);
a(m+2) = a(m+1) + (da(m+1) * 3.154e7);
end
e = e(1:end-1);
a = a(1:end-1);
plot(T,e)
hold on
0 Kommentare
Akzeptierte Antwort
Clay Swackhamer
am 10 Mai 2022
Hi AJ,
I'm not entirely sure about your question, since you ask to "plot the end points of these variables (a, e, de, da) against Qe" however Qe is a scalar (just a single number) in your code. So maybe you want to plot the variables (a, e, de, da) against Qe, while varying Qe from 6 to 15? That is what I did below. Hope it helps.
%% plotting_endpoints_from_arrays
%% Setup
close all
clear
clc
tic
format long
%% Loop over Qe
Qe = 6:1:15
% Run the calculation one time for each value of Qe
for i = 1:1:length(Qe)
M = 10000002;
a = zeros(M,1);
e = zeros(M,1);
da = zeros(M-1,1);
de = zeros(M-1,1);
T = [0:10000000];
e(1) = 0.0549;
a(1) = 0.3844e9;
for m = 0:10000000
de(m+1) = -(4.04562756e41 + ((2.75561858e40)/Qe(i))) * ((a(m+1))^(-13/2)) * e(m+1);
da(m+1) = (((8.09125512e41)*(e(m+1)^2)) + ((1.16026046e40)/Qe(i))) * (a(m+1))^(-11/2);
e(m+2) = e(m+1) + (de(m+1) * 3.154e7);
a(m+2) = a(m+1) + (da(m+1) * 3.154e7);
end
e = e(1:end-1);
a = a(1:end-1);
% Save endpoints
aEnd(i) = a(end);
eEnd(i) = e(end);
deEnd(i) = de(end);
daEnd(i) = da(end);
end
%% Plot endpoints of each variable vs Qe
subplot(2,2,1)
plot(Qe,aEnd, 'bo')
title('a vs Qe')
subplot(2,2,2)
plot(Qe,eEnd,'bo')
title('e vs Qe')
subplot(2,2,3)
plot(Qe,deEnd,'bo')
title('de vs Qe')
subplot(2,2,4)
plot(Qe,daEnd,'bo')
title('da vs Qe')
toc
2 Kommentare
Clay Swackhamer
am 11 Mai 2022
Glad it helped. If this answers your question can you go ahead and accept the answer above? Thanks
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!