Plotting end points from different arrays

3 views (last 30 days)
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

Accepted Answer

Clay Swackhamer
Clay Swackhamer on 10 May 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 Comments
AJ99
AJ99 on 11 May 2022
Apologies for the wording of the question. I struggled to explain it well but this is incredibly useful thanks! The final value in the array is suposed to be the values after 10 million years. So i was tying to plot the different values that we would get in 10 million years with different values for Q.
Clay Swackhamer
Clay Swackhamer on 11 May 2022
Glad it helped. If this answers your question can you go ahead and accept the answer above? Thanks

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!