Plotting ODE solutions for a single time point
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have plotted the solution to four odes against time.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/195581/image.jpeg)
I now want to plot results for a single time point. Such as for when t=5, i want to plot c_{j}(5) against j. Is there a short command that can do this using the code i have written
function f = beckerdorin(t,C)
a=0.5;
b=1.5;
sigma=0.5;
f(1,1)= b*(C(4)+ C(3)+ 2*C(2))-a*C(1)*(2*C(1)+C(2)+C(3));
f(2,1)= a*(C(1))^2 - b*C(2) - a*C(1)*C(2) + b*C(3)-2*sigma*(a*C(2)^2-b*C(4));
f(3,1)= a*C(2)*C(1)-b*C(3)-a*C(3)*C(1)+b*C(4);
f(4,1)= a*C(3)*C(1)-b*C(4)+sigma*(a*C(2)^2-b*C(4));
end
Plotting
clf
[tv,c] = ode45('beckerdorin',[0,3],[10,0,0,0]);
figure(2)
plot(tv,c(:,1),'r');hold on
plot(tv,c(:,2),'b');hold on
plot(tv,c(:,3),'y');hold on
plot(tv,c(:,4),'g');
legend('C(1)','C(2)','C(3)','C(4)')
xlabel('Time t')
ylabel('c_{j}(t)')
0 commentaires
Réponses (1)
Star Strider
le 11 Sep 2018
It requires that you slightly change your ode45 call, then use the solution structure with the odextend (link) function:
sln = ode45(@beckerdorin,[0,3],[10,0,0,0])
tv = sln.x';
c = sln.y';
figure(2)
plot(tv,c(:,1),'r');hold on
plot(tv,c(:,2),'b');hold on
plot(tv,c(:,3),'y');hold on
plot(tv,c(:,4),'g');
legend('C(1)','C(2)','C(3)','C(4)')
xlabel('Time t')
ylabel('c_{j}(t)')
slnxtd = odextend(sln, @beckerdorin, 5); % Extend Integration To ‘t=5’
c_5 = slnxtd.y(:,end) % Values Of ‘c’ At ‘t=5’
c_5 =
2.02359968542774
1.3649852291002
0.920727887972237
0.621061548113791
2 commentaires
Star Strider
le 11 Sep 2018
My pleasure.
What are you referring to? I do not see ‘j’ defined anywhere in your code. I have no idea what it is. It only appears as part of a character vector in your ylabel call.
You asked how to evaluate your ‘beckerdorin’ function at ‘t=5’, and I provided a way to do that.
I leave the rest to you.
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!