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

MATH12225 Applied Computational Modelling

Term 2 2016 Assignment 1


Due Fri. 12 Aug. 2016
1. Assignment Workings:
All answers require a clear justification in order to receive marks. For each question,
provide complete step-by-step workings that clearly show the means by which the
solutions were obtained. Trial and error will not be accepted as a justification.
However, it is a good idea to check your answers where you are able.

Because this assignment requires MATLAB programming, you need to type your
source codes and detailed workings and include final results (including plots if
required) in each question. Therefore no hand-written materials will be accepted.

2. Assignment Submission:
Please organise the Assignment as follows:
Scan these into a "single".pdf file. You can reduce the file size by up to 50% as a
jpeg option when saving the file. Use a low scan resolution of 75 or 150 dpi for
individual pages to keep the combined file below a few MB so you do not run into file
size errors in the mail program (files above 8 MB will be rejected and the student
asked to resubmit the file within the size limit). Submit the single file through Moodle
in the Assignment Submission page.
Contact your lecturer/tutor if you require further assistance with this.

3. Grading:
Assignment questions are marked on the workings to justify the answer and the
correctness of the answer for a usual total of 3 point per question. The file is
annotated and sent back to you so you can see where you went wrong, if anywhere.

4. Assignment Release:
The Assignments will be released two weeks after the due date. Students can collect
assignment feedback through Moodle. The solutions will be posted on the course
website after all assignments are marked. Discussion about Assignment questions
on the Discussion Forum is not allowed until after the solutions are released. Once
the solutions are released, discussion is most welcome to refine and clarify your
learning.

Please note that the questions in the assignment are based on the weekly
work in the course.
Week 1: Questions 1
Week 2: Questions 2-3
Week 3: Questions 4-7
Week 4: Questions 6, 8-10
MATH12225 Term 2 2016
Assignment 1 - Due Fri. of Week 5

Questions (total of 10 questions. Each carries 3 marks)

1 Demonstrate numerically the validity of the following expression

sin ( 17 )= 82 a 2(b+ a)
2

where

a= 17 17

c= 17+ 17

b=34 +6 17+ 2 ( 171 ) a8 c 2

2 Solve the following system of equations using the MATLAB function inv and also using
the operators \ in the command window:

2 x 3 y z t 11
5 x y 2 z 3t 25


4 x 3 y 2 z 3t 8
3x 4 y 5 z 2t 18

Verify your solution using matrix multiplication.

3 Input the matrices

[ ] [ ]
2 0 1 2 1 4
A= 1 1 2 and B= 0 1 3
3 1 1 3 2 1

(a) Verify that det ( A ) det ( B )=det ( AB)


A
(b) Verify that det ( T )=det ( A )

A
(c) Verify that det (1)=1 /det ( A )

y1 sin x y2 sin( x3 )
4 Write a MATLAB script to produce the graphs of the functions and
in the range of -5:0.02:5 using the same axes. Use the MATLAB functions xlabel,
ylabel, legend and title to annotate your graph clearly.

1
5 Use the surf function to plot z= for x =-5:0.5:5 and y =-5:0.5:5.
1+ x 2 + y 2

6 Write a MATLAB script to plot the function of f(x) given by:

{
x 2 2 / 4 x> /2
8cos x /2 x /2
f ( x )=
2
x 2 x < /2
4

x varies between - and with 100 data points.

Solution
x= -pi:100:pi ;
for i = 1:length(x)
if x(i)>pi./2
y(i)= x.^2-(pi.^2)./4;
if x(i)>= -(pi./2) && x(i)<=(pi./2)
y(i)=8*cos(x);
else
y(i)=(pi.^2)./4 x.^2;
end
end
plot(x,y);
xlabel(x);
ylabel(y);
7 For x=0:10 calculate y = cos(x), use fopen and fprintf to write x and y data into a
file named my_cos_data.dat. Then use fopen and fscanf to read the x and y
data. Show the data in 2 columns.

8 Write a function which accepts a students mark M in one course as a single input argument,
convert it to the grade G according to the following definitions:
M 85 , G = HD;
75 M <85 , G = D;
65 M <75 , G = C;
50 M <65 , G = P;
M< 50 , G = F;

Then write another function taking the grade G as a single input argument, and then display
the following message on the screen:
for G =HD, write Excellent
for G = D; write Very good
for G = C; write Well done
for G = P; write You passed
for G = F; write Better try again
if not the grade shown above, write invalid grade\n

Use switch statement in this function. Test your functions.


Solution
M=0:100:1;

prompt = 'Enter number:';


M = input(prompt);
if M<=0
disp = (' please enter number greater than 0:');

if M>=85
disp(Excellent);
elseif M>=75 && M<85
disp(Very good);

elseif M>=50 && M<65


disp(Well done);

elseif M<50
disp(Better try again);

else
disp(invalid grade\n);
end
end
9 Write a MATLAB script to find and display how many values are less than 10 within the
following matrix.

[ ]
12 5 9 0 18 6
2 34 56 1 2 15
88 2 32 12 1 8
A=
13 54 23 9 10 45
21 6 9 15 61 8
5 16 0 6 21 73

Soulution
A = [12 5 9 0 18 -6;2 34 56 1 -2 15;88 2 32 -12 1 -8;13 -54 23 9 10 45;21 6 9 15 61 8;5 16 0
6 21 73]
B=A;
D=1;
[m,n] = size(A) ;
for i = 1:m
for j = 1:n
if A(i,j) < 10
C= 1+D;
disp(C);

10 In MATLAB, the function mod(a,m) returns the remainder after division of a by m,


where a is the dividend and m is the divisor. Arguments a and m should be integers. For
example mod(12,5)= 2 since 12=2 5+2 , the remainder after 12 is divided by 5 is 2.
Similarly mod(24,5)=4, mod(7,5)=2 and mod(15,5)=0. Write a script using the
function mod to print the numbers between 0 and 50 which are not multiples of 3.

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