from
ODE Phase Plane
by Gabriel Alcantara
Simple script to show the use of ODE function to solve ordinary differential equations.
|
| odem()
|
function odem()
% Simple and ilustrative script to show the use of ODE function to
% solve ordinary differential equations.
% The classic example of the Van der Pol oscilator was used here.
% The script shows two plots; the time response and the phase plane for
% different initial conditions depending on the coordinates of the mouse
% pointer.
init = [0 0]; % Initial Conditions vector
initt = 0; % Timespan
finalt = 20;
butt=1;
while ((isempty(init))) || (butt ~=3) % Right click ends script.
[T Y]=ode45(@vdp1,[initt finalt],init); % Use of ode45 ('help ode45');
figure(2);
plot(T,Y); xlabel('time');title('Time Response');
legend('x','xdot',2);
figure(1);
plot(Y(:,1),Y(:,2));xlabel('x');ylabel('xdot'); title('Phase Plane');
hold on;
[initx inity butt]=ginput(1);
init=[initx inity];
end
close(1);close(2);
end
function Xdot=d_eq(t,X) % Differential Equation Definition
%(if ode1.m is not installed, see 'help ode45')
x=X(1); % Variable vectors
y=X(2);
% Van der Pol differential equation:
Xdot(1)=y;
Xdot(2)=(1-x^2)*y-x;
Xdot=Xdot'; % Result vector
end
|
|
Contact us at files@mathworks.com