Professional Documents
Culture Documents
Fisika
Semester Ganjil TA 2016/2017
Kania Nur Sawitri, S.Si, M.Si
Outline
Pendulum solution using the euler method
Eulers Method
y
yi 1 yi f xi , yi h
True Value
h xi 1 xi
yi
h
Step size
xi
xi+1
Pendulum solution
+
+
Initial condition:
=1m
= 10
=0.04 s
= 1 to 250
code
clear;
clc;
length= 1;
g=9.8; %inisiasi
npoints = 250;
dt = 0.04;
omega = zeros(npoints,1);
theta = zeros(npoints,1);
time = zeros(npoints,1);
theta(1)=0.2;
for step = 1:npoints-1
omega(step+1) = omega(step) - (g/length)*theta(step)*dt;
theta(step+1) = theta(step)+omega(step)*dt ;
time(step+1) = time(step) + dt;
end
plot(time,theta,'r' );
xlabel('time (seconds) ');
ylabel('theta (radians)');
Graph
+
+
code
clear;
clc;
length= 1;
g=9.8;
npoints = 250;
dt = 0.04;
omega = zeros(npoints,1);
theta = zeros(npoints,1);
time = zeros(npoints,1);
theta(1)=0.2;
for step = 1:npoints-1
omega(step+1) = omega(step) - (g/length)*theta(step)*dt;
theta(step+1) = theta(step)+omega(step+1)*dt;
time(step+1) = time(step) + dt;
end
plot(time,theta,'r' );
xlabel('time (seconds) ');
ylabel('theta (radians)');
Graph
Runge-Kutta 2
Method
Order
dy
f ( x, y ), y (0) y0
dx
http://numericalmethods.
For
nd
yi 1 yi a1k1 a 2 k 2 h
where
k1 f xi , yi
k2 f xi p1h, yi q11k1h
12
Heuns Method
Heuns method
Slope f xi h, yi k1h
Here a2=1/2 is
1
chosen
a
yi+1, predicted
Slope f xi , yi
2
p1 1
q11 1
Average Slope
yi
1
f x i h , y i k1 h f x i , y i
2
resulting in
1
1
yi 1 yi k1 k2 h
2
2
where
xi
xi+1
k 1 f x i , y i k 2 f x i h, y i k 1 h
code
clear;
length= 1;
g=9.8;
npoints = 250;
dt = 0.04;
omega = zeros(npoints,1);
omega_dash=zeros(npoints,1);
theta = zeros(npoints,1);
theta _dash=zeros(npoints,1);
time = zeros(npoints,1);
theta(1)=0.2;
for step = 1:npoints-1
omega_dash= omega(step) 0.5*(g/length)*theta(step)*dt;
theta_dash= theta(step)+0.5*omega(step)*dt
omega(step+1) = omega(step) - (g/length)*theta_dash*dt;
theta(step+1) = theta(step)+omega_dash*dt
time(step+1) = time(step) + dt;
end
plot(time,theta,'r' );
xlabel('time (seconds) ');
ylabel('theta (radians)');
graph