You are on page 1of 3

ENG1060 Computing for Engineers

Laboratory No.9 Page 1 of 3




This laboratory comprises 2% of your final grade. During your lab session,
you will be assessed on your programming style as well as the
results produced by your programs. Save your work in M-Files called
lab8t1.m, lab8t2.m etc
The questions are designed to test your recollection of the lecture material
up to and including week 10.

Note: Some of the functions presented would be new to you. You can use
the MATLAB help system to learn more about them.

Task1 1 mark
Consider the following Ordinary Differential Equation (ODE):
3
8
3
y
e
dt
dy
t
=

Find y(3) by hand using a step size h=1, and the initial condition of y(0)=3 using
the following methods:

(a) Eulers method

(b) Midpoint method

(c) Heuns method





Faculty of Engineering
Semester 1 - 2014
ENG1060 Computing for Engineers

Laboratory No. 9

ENG1060 Computing for Engineers
Laboratory No.9 Page 2 of 3

Task 2 2 marks
(a) Write an M-file that uses the Eulers method to find y(3) using a step size
of h=1, 0.75, 0.5 and 0.001 using an initial condition y(0)=3.
Note: Use ODE from Task 1

(b) Plot the results for all step sizes from part (a) and the analytical solution on
the same graph. The analytical solution is shown below:
t
t
e e y
3
8
11
24
11
9

+ =


(c) For each step size, calculate the absolute error between the Eulers
method estimate of y(3) and the analytical result. Print the results to the
command window.


Task 3 2 marks
(a) Write a function that uses the Heuns method to find y(t) with a step size h,
defined by the user as an input. Your function should start as follows:
function [t,y] = heun(dydt, tspan, y0,h)

(b) Write a function that uses the Midpoint method to find y(t) with a step size
h, defined by the user as an input.
function [t,y] = midpoint(dydt, tspan, y0,h)


Task 4 2 marks
(a) Write an M-file that uses the functions written in Task 3 to compare the
y(3) found using Heuns method and Midpoint method by using step sizes
of h=1, 0.75, 0.5 and 0.001 with an initial condition y(0)=3 .

Hint: You might want to plot a graph to show the comparisons

(b) Compare your answers from (b) with the built-in MATLAB function ode45.

Note: Use ODE from Task 1


ENG1060 Computing for Engineers
Laboratory No.9 Page 3 of 3

Task 5 3 marks
The material chosen for the body panels of an automobile will be subjected to
cyclic loading (alternating positive and negative forces or stresses) during use.
To test the materials behaviour in the laboratory under such cyclic loading, the
force acting on the material is measured over time. A computer precisely
determines when the material sample fractures. The equation describing the
loading is:
) 2 cos( ) sin(
2 1
t F t F
dt
df
+ =

where F
1
= 34 kN, F
2
= -18 kN and = 33 rad/s.

The material was observed to fracture after 3 hours, 15 minutes and 5 seconds.

Write an M-file that uses ode45 and a step size of 0.01 seconds to determine
what the force acting on the material was at the instant it fractures.

You might also like