5 Source code
function nma_project_511()
% This function solves the Van Der Pol nonlinear ode
% numerically using Matlab's ode45.
%
% Final project for 511, CSUF, spring 2009. Instructor: Dr Oh, Sang June
%
% Written by : Nasser M. Abbasi
% Van Der Pol ode is x''(t) - c (1-x^2(t)) x'(t) + k x(t) = 0
t = 0:0.001:100; % time scale
c = 1;
k = 1;
x0 = 10;
v0 = 3;
[t,x] = ode45( @rhs, t, [x0,v0]);
subplot(2,1,1);
plot(t,x(:,1));
xlabel('t'); ylabel('x(t)');
title(sprintf('Van Der Pol, position vs, time, c=%3.2f, k=%3.2f',c,k));
subplot(2,1,2);
plot(x(:,1),x(:,2));
xlabel('x(t)'); ylabel('v(t)');
hold on;
plot(x0,v0,'*r','MarkerSize',10);
title(sprintf('Phase portait showing limit cycle. x(0)=%3.2f, v(0)=%3.2f',x0,v0));
axis equal
hold off;
function dxdt=rhs(t,x)
dxdt_1 = x(2);
dxdt_2 = c*(1-x(1)^2)*x(2)-k*x(1);
dxdt = [dxdt_1 ; dxdt_2];
end
end
The file to download is
nma_project_511.m