Analysis of Cyclic Fatigue Failure Data

Nanyang Technological University
School of Chemical and BioMedical
Engineering
Division of Bioengineering

BG2802 Bioengineering Year 2 Lab
Lab Report

Analysis of Cyclic Fatigue Failure Data
using Least-square Regression

Author:
Yang WANGa
a

Matriculation Number: U1220560J

19 Febuary, 2013

Table of Contents


1 Background and Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1 Euler’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 4th order Runge-Kutta method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 Experiment Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 Results and Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.1 Euler’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2 4th order Runge-Kutta Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3 Comparison and Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.4 Epidemic Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1

2
2
2
2
2

3
9
9
10
11
12
12

2

1

Background and Introduction

Solving differential equations is frequently required in handling engineering problems,
however solving those equations by hands is not usually that easy. In many cases, there is no
analytical solutions to some differential equations, ordinary or partial. Numerical methods
to approximate the analytical solutions therefore is widely applied to get better results and
simulations. In this experiment on computational methods for numerical analysis, we will
use Matlab to apply Euler’s method and 4th order Runge-Kutta method for some data

approximation. By comparing the outcomes of these methods we might able to tell the
advantages and limitations in both cases. The third part of this experiment is to apply these
methods to model a epidemic incident. By the aforementioned methods we will get a better
understanding on the numerical analysis algorithms and apply these understandings into
solving real cases in the future.

2

Objectives
There are three objectives for this experiment.

First
Learn to use Matlab to compute solution of differential equations using Euler’s method
and 4th order Runge-Kutta method.
Second
Study the effect of step size used in Euler’s method and 4th order Runge-Kutta method
have on the solution of ODEs.
Third
Apply the numerical methods on a simple epidemic spreading model.


3
3.1

Theories
Euler’s Method
For a general initial value problem:
dy
= f (t, y),
dt
y(0) = y0
y′ =

for a stepping size h, the Euler’s method for approximation gives
yk+1 = yk + hf (tk , yk ),
k ∈ {N ∩ [0, M − 1)},
b−a
h=
M
by this, a series of points can be plotted, which is the approximation of the original
function curve.

3.2

4th order Runge-Kutta method
for an problem with initial condition:

3

dy
= f (t, y)
dt
y(0) = y0
the 4th order Runge-Kutta method approximation uses the formula
yk+1 = yk +

h
(k1 + 2k2 + 2k3 + k4 )
6

consider the equation
yi+1 = yi + h


4


an kn

n=1

known

y|t=t1 = yi
and
h = ti+1 − ti
by expanding with 4th order Taylor series


1 d2 y
dy
(t


t
)
+
(ti+1 − ti )2
yi+1 = yi +
i+1
i
dt ti ,yi
2! dt2 ti ,yi


1 d3 y
1 d4 y
3
+
(ti+1 − ti ) +
(ti+1 − ti )4
3! dt3 ti ,yi
4! dt4 ti ,yi
]

[

4

1 d(n) y
n
(ti+1 − ti )
= yi +
n! dt(n) ti ,yi
n=1
]
4 [

1 (n−1)
n
= yi +
f
(ti , yi )h
n!
n=1


4

and the general solution set is

k1



k2
k3



k4

= f (ti , yi )
= f (ti + 12 h, yi + 12 k1 h)
= f (ti + 21 h, yi + 12 k2 h)
= f (ti + 21 h, yi + 12 k3 h)


Experiment Procedures

1. Matlab Program for Euler’s Method
(a) Euler.m
function [tout, yout] = Euler(FunFcn, tspan, y0, ssize)
% FunFcn is the function to be solved
5

% tspan is the interval
% y0 is the initial conditions
% ssize is the step size

10

4
% Initialization
15

clf

t0 = tspan(1); %Start point
tfinal = tspan(2); %End point

20

i f (nargin < 4), ssize = (tfinal - t0)/100; end %calculate step size if
h = ssize;
25

t = t0;
y = y0(:);
30

tout = t;
yout = y.’;

35

% The main loop
while (t < tfinal)
40

i f t + h > tfinal, h = tfinal - t; end
% Compute the slope
s1 = feval(FunFcn, t, y); s1 = s1(:); % s1=f(t(k),y(k))

45

t = t + h;
y = y + h*s1; % y(k+1) = y(k) + h*f(t(k),y(k))
50

tout = [tout; t];
yout = [yout; y.’];
end;

(b) f Euler.m
function z = f(t, y)
z = (t - y)/2; %DonŠt forget the ; at the end of the line
5

return

(c) Run Euler.m
%Define the parameters
tspan = [0 3];
5

y0 = 1;
h = 1/32;

5

%Call the Euler solver
10

[tout, yout] = Euler(’f’, tspan, y0, h);
figure(2);
15

plot(tout,yout)
t i t l e ([’Euler s Method Method using h=’, num2str(h), ’ by Stephen’]);
%To show the value of yout at t = 3 in the command window

20

[m n] = s i z e (yout);
yout(m)

2. Matlab program for 4th order Tunge-Kutta Method
(a) rk4.m

5

10

15

20

25

30

35

40

function [tout, yout] = rk4(FunFcn, tspan, y0, ssize)
% FunFcn is the function to be solved
% tspan is the interval
% y0 is the initial conditions
% ssize is the step size
% Initialization
t0=tspan(1);
tfinal=tspan(2);
pm = sign(tfinal - t0);
i f nargin < 4, ssize = (tfinal - t0)/100; end
i f ssize < 0, ssize = -ssize; end
h = pm*ssize;
t = t0;
y = y0(:);
% We need to compute the number of steps.
dt = abs(tfinal - t0);
N = f l o o r (dt/ssize) + 1;
i f (N-1)*ssize < dt
N = N + 1;
end
% Initialize the output.
tout = zeros(N,1);
tout(1) = t;
yout = zeros(N, s i z e (y,1));
yout(1,:) = y.’;
k = 1;
% The main loop
while (k < N)
i f pm*(t + h - tfinal) > 0
h = tfinal - t;
tout(k+1) = tfinal;
else
tout(k+1) = t0 +k*h;
end
k = k + 1;
% Compute the slopes
s1 = feval(FunFcn, t, y); s1 = s1(:);
s2 = feval(FunFcn, t + h/2, y + h*s1/2); s2=s2(:);
s3 = feval(FunFcn, t + h/2, y + h*s2/2); s3=s3(:);

6

45

s4 = feval(FunFcn, t + h, y + h*s3); s4=s4(:);
y = y + h*(s1 + 2*s2 + 2*s3 +s4)/6;
t = tout(k);
yout(k,:) = y.’;
end;

(b) f rk.m
function z = f(t, y)
z = (t - y)/2; %DonŠt forget the ; at the end of the line
5

return

(c) Run rk4.m
%Define the parameters and constants
tspan = [0 3];
5

y0 = 1;
h = 1/16;
%To call the rk4 solver

10

[tout, yout] = rk4(’f’, tspan, y0, h); %Results from rk4 is stored in
figure(2);
15

plot(tout,yout)
t i t l e ([’Runge Kutta Method using h=’, num2str(h), ’ by Stephen’]);
%To show the value of yout at t = 3 in the command window

20

[m n] = s i z e (yout);
yout(m)

3. Epidemic Model
(a) Parameter adjustment Euler P5.m and rk4 P5.m , define new function f2.m
function [tout, yout] = Euler(FunFcn, tspan, y0, ssize)
% FunFcn is the function to be solved
5

% tspan is the interval
% y0 is the initial conditions
% ssize is the step size

10

% Initialization
15

clf
t0 = tspan(1); %Start point

7
tfinal = tspan(2); %End point
20

i f (nargin < 4), ssize = (tfinal - t0)/100; end %calculate step size if
h = ssize;
25

t = t0;
y = y0(:);
30

tout = t;
yout = y.’;

35

% The main loop
while (t < tfinal)
40

i f t + h > tfinal, h = tfinal - t; end
% Compute the slope
s1 = feval(FunFcn, t, y); s1 = s1(:); % s1=f(t(k),y(k))

45

t = t + h;
y = y + h*s1; % y(k+1) = y(k) + h*f(t(k),y(k))
50

tout = [tout; t];
yout = [yout; y.’];
end;

5

10

15

20

function [tout, yout] = rk4(FunFcn, tspan, y0, ssize)
% FunFcn is the function to be solved
% tspan is the interval
% y0 is the initial conditions
% ssize is the step size
% Initialization
t0=tspan(1);
tfinal=tspan(2);
pm = sign(tfinal - t0);
i f nargin < 4, ssize = (tfinal - t0)/100; end
i f ssize < 0, ssize = -ssize; end
h = pm*ssize;
t = t0;
y = y0(:);
% We need to compute the number of steps.
dt = abs(tfinal - t0);
N = f l o o r (dt/ssize) + 1;
i f (N-1)*ssize < dt
N = N + 1;
end
% Initialize the output.
tout = zeros(N,1);

8

25

30

35

40

45

5

tout(1) = t;
yout = zeros(N, s i z e (y,1));
yout(1,:) = y.’;
k = 1;
% The main loop
while (k < N)
i f pm*(t + h - tfinal) > 0
h = tfinal - t;
tout(k+1) = tfinal;
else
tout(k+1) = t0 +k*h;
end
k = k + 1;
% Compute the slopes
s1 = feval(FunFcn, t, y); s1 = s1(:);
s2 = feval(FunFcn, t + h/2, y + h*s1/2); s2=s2(:);
s3 = feval(FunFcn, t + h/2, y + h*s2/2); s3=s3(:);
s4 = feval(FunFcn, t + h, y + h*s3); s4=s4(:);
y = y + h*(s1 + 2*s2 + 2*s3 +s4)/6;
t = tout(k);
yout(k,:) = y.’;
end;
function z = f2(t, y)
L = 25000;
k = 0.00003;
z = k*y*(L - y)/2;
return

(b) Run Euler approximation Run Euler P5.m
%Define the parameters
tspan = [0 20];
5

y0 = 250;
h = 0.2;
%Call the Euler solver

10

[tout, yout] = Euler(’f2’, tspan, y0, h);
figure(2);
15

plot(tout,yout)
t i t l e ([’Euler s Method Method using h=’, num2str(h), ’ by Stephen’]);
%To show the value of yout at t = 3 in the command window

20

[m n] = s i z e (yout);
yout(m)

(c) Run 4th order Tunge-Kutta approximation Run rk4 P5.m
%Define the parameters and constants

9
tspan = [0 20];
5

y0 = 250;
h = 0.2;
%To call the rk4 solver

10

[tout, yout] = rk4(’f2’, tspan, y0, h); %Results from rk4 is stored in
figure(2);
15

plot(tout,yout)
t i t l e ([’Runge Kutta Method using h=’, num2str(h), ’ by Stephen’]);
%To show the value of yout at t = 3 in the command window

20

[m n] = s i z e (yout);
yout(m)

5
5.1

h
1
1/2
1/4
1/8
1/16

Results and Analysis
Euler’s Method

t=3
1.3750
1.5339
1.6043
1.6374
1.6536

10

5.2

h
1
1/2
1/4
1/8
1/16

4th order Runge-Kutta Method

t=3
1.6702
1.6694
1.6694
1.6694
1.6694

11

5.3

Comparison and Comments

Obviously 4th order Runge-Kutta Method provided a better and faster simulation than
Euler’s method, the accuracy of this method is higher too. However the calculation burden
for computer and computational duration is longer too.

12
Euler’s Method 4th order Runge-Kutta Method
t = 20 2.3625 × 104
2.3702 × 104

5.4

6

Epidemic Model

Conclusion

This experiment practice some fundamental approximation using Matlab on Euler’s
method and 4th order Runge-Kutta method. In real cases there are more complicated conditions to be considered. In the last part of the experiment, by modelling the spreading and
increasing of number of people that infected in an epidemic, we noticed a typical ‘S’-type
growth, which is similar and common in any natural growth phenomenon. Although computer simulation can only give us a rough idea and sometimes it might not be accurate, as
the algorithm developing and new methods coming up, it will surely be a strong and useful
tool in handling huge amount of data in the coming days.