ode 45 plot of intermediate vraibles of differential equations
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Thayumanavan
il 15 Feb 2014
Commentato: Thayumanavan
il 16 Feb 2014
clear all
clc;
Tspan =[0 1];
X0=[1.0; 1]; % Initial condition
%solving the differential Equation
[t,x]=ode45(@myfunc,Tspan,X0);
%Plotting the figures figure(1)
subplot(2,1,1)
plot(t(:,1),x(:,1))
xlabel('t');
ylabel('x1');
grid on
subplot(2,1,2)
plot(t(:,1),x(:,2))
xlabel('t');
ylabel('x2')
grid on
% subplot(3,1,3) % plot(t(:,1),P) % xlabel('t'); % ylabel('P') % grid on
The ode function is:
function dv=myfunc(t,x)
P=sqrt(x(1)+x(2));
%The Diffenrential Equation
dv=[ (x(1))+(x(2)*x(2))+P;%x1dot Equation
x(1)-x(2); ]; % x2dot Equation
I want to plot P also wrt time like x1 and x2.
Since the ode fucntion returns only the time and solution ie t and x (x1,x2) . How to get the P for plotting?.I tried declaring it global but in vein .Please help
0 Commenti
Risposta accettata
Mischa Kim
il 16 Feb 2014
Modificato: Mischa Kim
il 16 Feb 2014
Thayumanavan, after the ode45 call, compute P:
[t,x]=ode45(@myfunc,Tspan,X0);
P = sqrt(x(:,1) + x(:,2));
plot(t,P)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!