Why do the lines not plot to completion
2 views (last 30 days)
Show older comments
Mary Jean Savitsky
on 2 Dec 2020
Commented: Mary Jean Savitsky
on 3 Dec 2020
Any ideas on why the red and yellow line are stopping? I want them to go all the way down but I cant figure out what the issue is. It is a graph of Effectiveness over observable modulus and I copied my code below. I tried removing the xlim but that didnt work. Would love to hear any ideas! Thank you!
%% first order line
observ_mod=logspace(-2,1);
n=tanh(observ_mod)./observ_mod;
figure(2)
loglog(observ_mod,n)
xlim([-2 10])
ylim([-1 1])
hold on
%% Beta=2 line
F=0.5
b_2=2
syms theta(x)
equation_41b_2=odeToVectorField(diff(theta,2) == (F*theta)/(1+b_2*theta)); % Solves the equation 10.6.41b from the textbook
vector2=matlabFunction(equation_41b_2, 'vars', {'x','Y'}); % Determines the vector
solution2=ode45(vector2, [0 1], [.39 0]);
factor2=((1+b_2)/(F))*(solution2.y(2,:)); % Effective Factor First Order 1
observ_mod2=(factor2*F)/(1+b_2); % Observable Modulus First Order 1
%% Beta=5 line
b_5=5
syms theta(x)
equation_41b_5=odeToVectorField(diff(theta,2) == (F*theta)/(1+b_5*theta)); % Solves the equation 10.6.41b from the textbook
vector5=matlabFunction(equation_41b_5, 'vars', {'x','Y'}); % Determines the vector
solution5=ode45(vector5, [0 1], [.39 0]);
factor5=((1+b_5)/(F))*(solution5.y(2,:)); % Effective Factor First Order 1
observ_mod5=(factor5*F)/(1+b_5); % Observable Modulus First Order 1
% observ_mod=logspace(-2,1);
% n=tanh(observ_mod)./observ_mod;
%% Plotting
% loglog(factor1,1-observ_mod1)
loglog(factor2,1-observ_mod2)
loglog(factor5,1-observ_mod5)
% xlim([10^-2 10])
ylim([0.1 1])
title('Effectiveness Factor vs. Observable Modulus')
xlabel('Observable Modulus')
ylabel('Effectiveness Factor, n')
0 Comments
Accepted Answer
Ive J
on 2 Dec 2020
Increase integration interval in ode45:
solution2=ode45(vector2, [0 25], [.39 0]);
solution5=ode45(vector5, [0 25], [.39 0]);
More Answers (1)
Walter Roberson
on 2 Dec 2020
solution2=ode45(vector2, [0 1], [.39 0]);
factor2=((1+b_2)/(F))*(solution2.y(2,:)); % Effective Factor First Order 1
so factor2 will be set according to the output of the ode -- not according to the input of the ode.
loglog(factor2,1-observ_mod2)
and that factor2 will be used as the independent variable for the second plot, even though it is obviously a dependent variable. There is no solid reason ahead of time to expect that the output of the ode will have any particular range.
observ_mod2=(factor2*F)/(1+b_2); % Observable Modulus First Order 1
In practice your factor2 appear to be in strictly increasing order. Your observe_mod2 is calculated from that with a simple transformation. You use your factor2 as the x axis for your loglog() plot. That means that as long as factor2 is finely-enough sampled that you do not get visual artifacts, that you might as well instead just substitute factor2 values that you make up with linspace() or logspace() without ever having done the ode45(). In context, the only purpose of the ode45 is to establish the range of values to plot over, and you do not even want to use that range, so you might as well not even call ode45() .
See Also
Categories
Find more on Numerical Integration and Differential Equations 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!