0% found this document useful (0 votes)
19 views

Assignment 1

The document describes using the Runge-Kutta fourth order (RK4) method to numerically solve the Van der Pol oscillator equation in MATLAB. It defines the time interval, number of steps, initial conditions, and system of ordinary differential equations. A for loop implements the RK4 method to calculate the solution at each step. Finally, it plots the results.

Uploaded by

Muhammad Fahim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Assignment 1

The document describes using the Runge-Kutta fourth order (RK4) method to numerically solve the Van der Pol oscillator equation in MATLAB. It defines the time interval, number of steps, initial conditions, and system of ordinary differential equations. A for loop implements the RK4 method to calculate the solution at each step. Finally, it plots the results.

Uploaded by

Muhammad Fahim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Numerical Solution of Von Der Pol Equation with Rk4 in Matlab

clear;
%Define time interval and number of steps
a=0;
b=20;
n=1000;
%step size
h=(b-a)/n;
%k is the parameter in the given equation
k=0;
t=linspace(a,b,n+1);
%initail conditions
x(1)=2;
y(1)=0;
%system of linear ODEs
f=@(t,x,y)(y);
g=@(t,x,y)(k*y*(1-x^2)-x);
%Loop for the RK method of order 4
for i=1:n
k1=h*f(t(i),x(i),y(i));
l1=h*g(t(i),x(i),y(i));
k2=h*f(t(i)+h/2,x(i)+k1/2,y(i)+l1/2);
l2=h*g(t(i)+h/2,x(i)+k1/2,y(i)+l1/2);
k3=h*f(t(i)+h/2,x(i)+k2/2,y(i)+l2/2);
l3=h*g(t(i)+h/2,x(i)+k2/2,y(i)+l2/2);
k4=h*f(t(i)+h,x(i)+k3,y(i)+l3);
l4=h*g(t(i)+h,x(i)+k3,y(i)+l3);
x(i+1)=x(i)+(1/6)*(k1+2*(k2)+2*(k3)+k4);
y(i+1)=y(i)+(1/6)*(l1+2*(l2)+2*(l3)+l4);
end
%Finally plot the results
figure(1);
plot(x,y);
title('Von der pol pure linit cycle for k=0')
legend('Numerical solution','location','east')
figure(2);
plot(t,x,'--',t,y);
xlabel('time t');
ylabel('Solution of x & y');
legend('x','y','location','southeast')

1
2
3
4
5
6
7
8
9
10
The period of the limit oscillation of the Von Der Pol oscillator
clear;
kn=[0,0.3,0.6,1,1.3,1.6,2,2.3,2.6,3,3.3,3.6,4,4.3,4.6,5,5.3,5.6,6,6.3
,6.6,7,7.3];
Tn=[6.28,6.30,6.42,6.66,6.88,7.16,7.58,7.90,8.26,8.76,9.14,9.54,10.06
,10.48,10.90,11.46,11.88,12.30,12.88,13.32,13.76,14.34,14.80];
ks1=[0,0.3,0.6,1,1.3,1.6,2,2.3,2.6,3,3.3];
Ts1=2*pi*ks1.^0;
ks2=[0,0.3,0.6,1,1.3,1.6,2,2.3,2.6,3,3.3,3.6,4,4.3];
Ts2=2*pi*(1+1/16*ks2.^2);
kl1=[4.3,4.6,5,5.3,5.6,6,6.3,6.6,7];
Tl1=kl1*(3-2*log(2));
kl2=[1,1.3,1.6,2,2.3,2.6,3,3.3,3.6,4,4.3,4.6,5,5.3,5.6,6,6.3,6.6,7];
Tl2=kl2*(3-2*log(2))+7.0143*kl2.^(-1/3);
plot(kn,Tn,'o-',ks1,Ts1,'p--',ks2,Ts2,'+--',kl1,Tl1,'*--',kl2,Tl2,'r-
-')
axis([0,8,0,15])
title('preface')
xlabel('k')
ylabel('period')
legend('Numerical Solution','O(k) small k','O(k^2) small k','O(k)
large k','O(k^2) large k','location','southeast')

11

You might also like