フィルターのクリア

ode 45 plot of intermediate vraibles of differential equations

2 ビュー (過去 30 日間)
Thayumanavan
Thayumanavan 2014 年 2 月 15 日
コメント済み: Thayumanavan 2014 年 2 月 16 日
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

採用された回答

Mischa Kim
Mischa Kim 2014 年 2 月 16 日
編集済み: Mischa Kim 2014 年 2 月 16 日
Thayumanavan, after the ode45 call, compute P:
[t,x]=ode45(@myfunc,Tspan,X0);
P = sqrt(x(:,1) + x(:,2));
plot(t,P)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by