COSC1001/1901 Exam Solutions & Marking Scheme: MATLAB Computational Science, Exams of Computational Physics

The solutions and marking scheme for an exam in computational science using matlab, covering topics such as measuring acceleration due to gravity, random numbers, and oscillations in a hanging rope/chain. It includes matlab code snippets and explanations.

Typology: Exams

2012/2013

Uploaded on 02/20/2013

salagame
salagame šŸ‡®šŸ‡³

4

(3)

36 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COSC1001/1901 (Semester Two, 2008) Exam Solutions and Marking Scheme
Computational Science in MATLAB
COSC1001 (Normal) & COSC1901 (Advanced)
Exam Solutions and Marking Scheme
This exam assesses the entire course, with more emphasis for COSC 1001 placed on the early
part of the course (basic MATLAB) with question 3, and more emphasis for COSC 1901 placed
on the final two lectures with question 4.
1. Measuring acceleration due to gravity
This question assesses week 8 (ā€œReview the application of linear algebra to physical prob-
lemsā€, ā€œUnderstand the built-in matrix manipulation functionsā€ and ā€œApply matrix methods
to problems in linear algebra...ā€), week 3 (ā€œWrite user-defined functionsā€), week 4 (ā€œUnder-
stand the matrix datatypeā€) and week 7 (ā€œCalculate the accuracy of statistics drawn from
limited populationsā€)
(a) 3 marks
0.132g+ 0.13b+c= 0 (1)
0.572g+ 0.57b+c= 2 (2)
0.762g+ 0.76b+c= 4 (3)


0.1320.13 1
0.5720.57 1
0.7620.76 1



g
b
c

=

0
2
4

(4)
(b) 3 marks
>> A=[0.13^2 0.13 1; 0.57^2 0.57 1; 0.76^2 0.76 1];
>> y = [0; 2; 4];
>> gbc = inv(A)*y
(c) 2 marks
function g = calcg(t)
% This function computes the acceleration due to gravity, based on
% an experiment that includes sensors placed at 0, 1 and 2 m
A=[t(1)^2 t(1) 1; t(2)^2 t(2) 1; t(3)^2 t(3) 1];
gbc = A\[0; 2; 4];
g=gbc(1);
(d) 2 marks
display([’g = ’ num2str(mean(g)) ’ +/- ’ num2str(std(g)/length(g))])
2. Random Numbers This question assesses week 7 (all remaining points) and week 6 (ā€œgen-
erate a normal distribution from uniform deviatesā€.
(a) 2 marks
(Directly from lecture notes, week 7) We determine the area under the curve and ensure
that is equal to unity. Evaluation of the integral Rāˆž
0P(x)dx yields
Zāˆž
0
eāˆ’x/Ī» dx =hāˆ’Ī»eāˆ’x/Ī»iāˆž
0= 0 + Ī»=Ī»
1
pf3
pf4

Partial preview of the text

Download COSC1001/1901 Exam Solutions & Marking Scheme: MATLAB Computational Science and more Exams Computational Physics in PDF only on Docsity!

Computational Science in MATLAB

COSC1001 (Normal) & COSC1901 (Advanced)

Exam Solutions and Marking Scheme

This exam assesses the entire course, with more emphasis for COSC 1001 placed on the early part of the course (basic MATLAB) with question 3, and more emphasis for COSC 1901 placed on the final two lectures with question 4.

  1. Measuring acceleration due to gravity This question assesses week 8 (ā€œReview the application of linear algebra to physical prob- lemsā€, ā€œUnderstand the built-in matrix manipulation functionsā€ and ā€œApply matrix methods to problems in linear algebra...ā€), week 3 (ā€œWrite user-defined functionsā€), week 4 (ā€œUnder- stand the matrix datatypeā€) and week 7 (ā€œCalculate the accuracy of statistics drawn from limited populationsā€)

(a) 3 marks

  1. 132 g + 0. 13 b + c = 0 (1)
  2. 572 g + 0. 57 b + c = 2 (2)
  3. 762 g + 0. 76 b + c = 4 (3)

 

g b c

(b) 3 marks

A=[0.13^2 0.13 1; 0.57^2 0.57 1; 0.76^2 0.76 1]; y = [0; 2; 4]; gbc = inv(A)*y (c) 2 marks function g = calcg(t) % This function computes the acceleration due to gravity, based on % an experiment that includes sensors placed at 0, 1 and 2 m A=[t(1)^2 t(1) 1; t(2)^2 t(2) 1; t(3)^2 t(3) 1]; gbc = A[0; 2; 4]; g=gbc(1); (d) 2 marks display([’g = ’ num2str(mean(g)) ’ +/- ’ num2str(std(g)/length(g))])

  1. Random Numbers This question assesses week 7 (all remaining points) and week 6 (ā€œgen- erate a normal distribution from uniform deviatesā€.

(a) 2 marks (Directly from lecture notes, week 7) We determine the area under the curve and ensure that is equal to unity. Evaluation of the integral

0 P^ (x)^ dx^ yields ∫ (^) āˆž

0

eāˆ’x/Ī»^ dx =

[

āˆ’Ī»eāˆ’x/Ī»

]āˆž

0

= 0 + Ī» = Ī»

and thus we divide by Ī» (i.e. the area under the curve) to obtain the normalised expression for P (x). Using this expression for P (x), which takes the form

P (x) =

Ī»

eāˆ’x/Ī»

(b) 2 marks (Directly from lecture notes, week 7) We now compute the Area under the curve between 0 and some fixed value t. This area is, by construction, less than one, and is given by the expression (^) ∫ t

0

Ī»

eāˆ’x/Ī»^ dx =

[

āˆ’eāˆ’x/Ī»

]t 0

= āˆ’eāˆ’t/Ī»^ + 1

We can now use rand to generate a random Area between 0 and 1, and then invert the equation above to solve for t. Area = 1 āˆ’ eāˆ’t/Ī» eāˆ’t/Ī»^ = 1 āˆ’ Area āˆ’t/Ī» = log(1 āˆ’ Area) t = āˆ’Ī» log(1 āˆ’ Area)

(c) 2 marks

lambda=1; t=-lambda*(1-rand);

The histogram plot should look like a decaying exponential with several bins. (d) 3 marks The best code is: function times=pulses(N) times=sum(-log(1-rand(1000,N))); Acceptable code (for 2 marks) is: function times=pulses(N) for i=1:1000; t=-log(1-rand(1,N)); times(i)=sum(t); end (e) 1 marks pulses(1000) should have a Normal distribution by the Central Limit Theorem.

  1. (COSC 1001) Basic MATLAB

This question asesses most of weeks 1-4, with the exception of those parts assesed in question

(a) 4 marks

disp(e(M,M)) plot([v(:,M); 0],0:N) xlabel(’Displacement’) ylabel(’Link Number’) NB Marks will not be deducted for omitting labels on axes. Note that a student can still get full marks for this question if they can’t figure out part (b): they just have to assume that a function ChainMat is written.

(e) 3 marks

N=50;

for i=1:N A = ChainMat(i); e=eig(A) t(i)=2pi/sqrt(e(1))sqrt(1/9.8/i); end plot(t,’o’) xlabel(’N’); ylabel(’Period (s)’)

The oscillation period of a chain is close to the N = 50 period, or 1.68 s, and the oscillation period of a simple pendulum has an oscillation period of ∼2.01 s, so the ratio is about 0.84. NB Again, no marks should be deducted if the labelling and plotting symbols are ommited from the program.