Вы находитесь на странице: 1из 5

School of Mathematics and Statistics

University of New South Wales


MATH1151
Mathematics for Actuarial Studies and Finance 1A

MATLAB Computing Exercises 2014


The purpose of this handout is to help you prepare for the MATLAB Computing Test in week
10. Model solutions to all the exercises below will be available on UNSW Moodle from the
beginning of week 9.
You are expected to be familiar with the following MATLAB commands:
[ ]
:
.*
./
.^
sum
prod
max
min
rref
\
disp
format
eps
@(x)
fzero
fminbnd
plot
grid
title, xlabel,ylabel
polar
linspace
help
print -dps

create arrays
colon operator
element by element multiplication
element by element division
element by element power
sum
product
maximum
minimum
reduced row echelon form
matrix left-division operator
display a text message
change the format of screen output
relative machine precision
create an anonymous function
finds zero(s) of a function
finds a local minimum of a function
plots data points
put gridlines on a plot
annotations for a plot
polar plot
linearly spaced points
MATLABs online help function
save plot as postscript file

For the test, you also need to understand how to create and modify M-files using the MATLAB
editor. A brief guide explaining how to do this when for the questions during the test will be
available on UNSW Moodle.
The harder exercises are marked with an asterisk. Each test will contain four routine
questions and one harder one.

Exercises
1. Enter the following three vectors a, b and c, and evaluate the vector algebra expressions
2a + 13b and 12a 4c, if they exist:
a = [1, 2, 3, 4, . . . , 11] ,

b = [1, 3, 5, 7, . . . , 21] ,

c = [1, 4, 9, 16, 25, . . . , 100] .

2. Evaluate the sum


100
X
n=1

1
1
1
1
= 1 + + + +

.
n n
2 2 3 3
100 100

3. Evaluate the product


100
Y

(2)(2) (4)(4) (6)(6)


(200)(200)
(2n)2
=


.
(2n 1)(2n + 1)
(1)(3) (3)(5) (5)(7)
(199)(201)
n=1
4. Find the largest number in the infinite sequence a1 , a2 , a3 , . . . if
an =

n5
.
2n

5. Define the coefficient matrix A and the right-hand-side vector b for the linear system
4x1
3x1
18x1

x2 + 3x3
+ 3x2
+ 2x3
+ 3x2 + 5x3

+
+
+
+

2x4
4x4
3x4
8x4

= 3,
= 4,
= 2,
= 3.

Set up the augmented matrix [A | b], calculate the reduced row-echelon form R and
display the appropriate message: Linear systems has no solutions, Linear system
has a unique solution, Linear system has infinitely many solutions. (Decide
which case is appropriate just by looking at R. You are not asked to find a solution.)
6. Solve the linear system
3x1
4x2
x1
x1

2x2
+ x2

x3 + 2x4 + x5
+ 2x3
x5
+ 2x3 + x4
x3 + 4x4
+ 7x5

= 8,
= 15,
= 4,
= 1,
= 32.

Then calculate the residual vector Ax b and check if it zero.


7. Create a plot of the polynomial x5 9x3 + 2x 4 for 3 x 3.
8. Create a plot of the parametric curve



x = sin 2t +

t2

y = t
3

for

t ,
2

put gridlines on the plot and then save the plot in a PostScript file myplot.ps (using
print).
2

9. Create a plot of the polar curve


r = 5 4 cos(2) for ,
and then save the plot in a PostScript file myplot.ps (using print).
10. * Find all real solutions of the nonlinear equation
x3 = cos x + 2.
Your answer(s) should be correct to machine precision.
11. * The function
f : x 7 e

x2




sin 8x
,
3

has a global minimum at a unique point xmin and a global maximum at a unique point xmax .
Find xmin and xmax , correct to at least 5 significant figures.

University of New South Wales


School of Mathematics and Statistics
MATH1151
SESSION 1
2014
MATLAB COMPUTING TEST
SAMPLE VERSION
Students may not bring any materials to the test except for some writing paper and a
pen or pencil for rough working.
You may attempt the questions in any order, but you must create five files called q1.m,
q2.m, q3.m, q4.m, q5.m containing your answers to questions 1, 2, 3, 4, 5 respectively.
Each file must be a script M-file. Make sure that each file has the .m extension.
You must use small (lower case) letters; Q1.m etc. will not be processed.
Your test will be marked based on a hard copy of your M-file and of the output it produces
after the workspace has been cleared. For example, to test your answer to the first
question you should type clear all followed by q1 in the MATLAB command window.
Do not include the clear all command in your file q1.m.
The test may include one question that requires you to create a postscript file called
myplot.ps. You can view the contents of this file using the file browser (Dophin), or by
typing okular myplot.ps in a Linux terminal window.
Make sure you SAVE YOUR WORK REGULARLY. Do not create any folders; just
keep your files in your home (login) directory. Matlab will save files there by default.
Use semi-colons as appropriate to control what your script produces as output. Excessively long output may be penalised. But make sure your script displays the
answer(s) to the question!
You may use the built-in MATLAB help facilities.

The test questions are on the back of this sheet.

SAMPLE VERSION
Time allowed: 45 minutes.
Use semi-colons where appropriate.
1. Enter the following three vectors a, b and c, and evaluate the vector algebra expressions
2a 3b and 7a 4c, if they exist:
a = [1, 2, 3, 4, . . . , 11] ,

b = [20, 18, 16, 14 . . . , 2] ,

c = [1, 4, 9, 16, 25, . . . , 121] .

2. Evaluate the sum


50
X
41
43
99
101
2n + 1
=
+
+ +
+
.
2
2
2
2
1+n
1 + 20
1 + 21
1 + 49
1 + 502
n=20

3. Define the coefficient matrix A and the right-hand-side vector b for the linear system
6x1 + 4x2 x3 + x4
x1 2x2
+ x5
2x1 + 2x2 + 9x3 + 2x4
3x2
4x5
x1
2x3 2x4 + 5x5

= 5
= 3
= 8
= 11
= 3.

Set up the augmented matrix [A | b], calculate the reduced row-echelon form R and
display the appropriate message: Linear systems has no solutions, Linear system
has a unique solution, Linear system has infinitely many solutions. (Decide
which case is appropriate just by looking at R. You are not asked to find a solution.)
4. Create a plot of the polynomial x5 9x3 + 2x 4 for 3 x 3 put gridlines on your
plot and then save the plot in a PostScript file myplot.ps (using print).
5. * Find the unique point of R2 where the two curves
y = x3 5x 1 and y = 5 ex
intersect. The coordinates should be correct to machine precision.

This test paper and any rough work


must be handed back
at the end of the test.

Вам также может понравиться