ode 45 plot of intermediate vraibles of differential equations
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Thayumanavan
am 15 Feb. 2014
Kommentiert: Thayumanavan
am 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 Kommentare
Akzeptierte Antwort
Mischa Kim
am 16 Feb. 2014
Bearbeitet: Mischa Kim
am 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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations 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!