You are on page 1of 3

ENG1060 Computing for Engineers

Faculty of Engineering
Semester 1 - 2014

ENG1060 Computing for Engineers


Laboratory No. 2
This laboratory comprises 2% of your final grade. You will be assessed
during your laboratory session by the demonstrators. You will be assessed
on the quality of your programming style as well as the results produced by
your programs. Save your work in M-Files called lab2t1.m, lab2t2.m etc.
The questions are designed to test your recollection of the lecture material
in week 1 and 2. This laboratory will introduce you to MATLAB and cover
variables, matrices and plotting.
Note: Some of the functions presented would be new to you and you
should use the MATLAB HELP to learn it how to use them.
Task 1 1 mark
Using MATLAB, write an M-file that does the following:
(i) Creates a vector t ranging from 1 to 10 in steps of 0.5
(ii) Creates a vector theta that contains 19 elements ranging from 0 to .
(iii) Computes the following:
x = 2 sin( )
t
y = sin 2 ( )
4
Hint: You might use the MATLAB inbuilt function linspace

Laboratory No.2 (Week 3)

Page 1 of 3

ENG1060 Computing for Engineers

Task 2 2 marks
All points with coordinates x = rcos() and y = rsin(), lies on a circle with radius r.
Write a MATLAB code that creates a vector for with 9 values from 0 to 2 and
uses r = 2 to plot the coordinates of x vs y (using a red line) to check if a circle
with radius 2 is actually obtained (if not, what would you change in the code to fix
the problem).
Note: Ensure your plot is labelled
Task 3 2 marks
Using MATLAB and these two matrices
A=

100

10

B = ln(A)

a) Select just the second row of B


b) Evaluate the sum of the second row of B
c) Find the element-by-element square of matrix A
d) Form a 2X2 sub-matrix from A comprising of all the elements in the 2nd
& 3rd row and 1st & 3rd column
e) Evaluate the sum of the first row of A and divide it element-by-element
by the first three elements of the third column of B
Task 4 2 marks
When asked to provide a trigonometric solution, such as sine or cosine,
MATLAB uses a Taylor series as an approximate solution.
For example, the series solution for sin(x) and cos (x) are:

( 1)n

n =0

(2n + 1)!

sin ( x ) =

Laboratory No.2 (Week 3)

x 2 n +1

n
(
1) 2 n
cos( x ) =
x
n =0 (2n )!

Page 2 of 3

ENG1060 Computing for Engineers

Prior to the advent of modern computing, this series solution was used to provide
accurate estimates of sin(x) and cos(x). Now, computer programs use the same
technique to estimate sine.
a) Write an M-file which will calculate sin(/5) using from one to six terms
(for n up to 0, n up to 1 n up to 5) in the series solution. For each of the
six cases, compare the answer from the series solution to the answer
given from the MATLAB built-in function sin(x) as a percentage error.
b) Write an M-file program which calculates tan(x).
sin( x)
Note: Use the trigonometric identity tan( x) =
cos( x)
The program should use the first six terms (n up to 5). Calculate the Taylor
tan approximation values of x going from to in 0.1 increments. Plot
the absolute error between your Taylor tan(x) approximation and
MATLABs built-in tan function.
Note: Absolute _ error = approx true
Task 5 3 marks
A simply supported beam that is subjected to a constant distributed load w over
two-thirds of its length is shown below.

The deflection y, as a function of x, is given by the equations:


wx 3 16 2 2 64 4
2
for 0 x L
y=
Lx L x + L
24 LEI
9
81
3
y=

wL 3
40 2
4 3
2
2 x 6 Lx + L x L
54 EI
9
9

for

2
L x L
3

Where E is the elastic modulus, I is the moment of inertia and L is the length of
the beam.
For the case where L = 20m, E = 200 x 109 Pa, I = 348 x 10-6 m4, and w = 5 x 103
N/m, write a MATLAB code that plots the deflection of a beam (y) as a function of
the beam length (x) and use matrix addressing to find the maximum deflection of
the beam and where along the beam does it occur.
Laboratory No.2 (Week 3)

Page 3 of 3

You might also like