Finding the maximum y value for one graph
33 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Oskar
am 15 Dez. 2017
Beantwortet: Star Strider
am 15 Dez. 2017
I have created 2 graphs for my code but when I try to find the maximum y value I get the same answer for both graphs (it's the highest y value from the second graph both times as that has the highest y value overall).
if true
% code
end
time_period = [0 181324/20000];
initial = [0, 0];
[t,y]=ode45(@myode45function, time_period, initial);
plot(t,y(:,1)),title('Graph of y against t')
xlabel('t')
ylabel('y')
ymax=max(y(:,1));
disp(ymax)
Figure;
plot(t,y(:,2)),title('Graph of dy/dt against t')
xlabel('t')
ylabel('dy/dt')
ymax2=max(y(:,1));
ymax1=max(y(:,2));
disp('The maximum value of dy/dt is: ')
disp(ymax1)
disp('The corresponding value of t is: ')
ymax2=max(y(:,1));
disp(ymax2)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 15 Dez. 2017
I cannot run your code because I do not have your ODE function. However when I create an ODE function to work with it, you code appears to work.
If you want the index of the first maximum for each, ask max to return both outputs:
[ymax2,imax2] = max(y(:,1));
[ymax1,imax1] = max(y(:,2));
The second one is the index where the first maximum occurs. You can correctly reference the corresponding time that way:
ymax2=max(y(imax1,1));
0 Kommentare
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!