필터 지우기
필터 지우기

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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by