


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 4
This page cannot be seen from the preview
Don't miss anything!



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.
(a) 3 marks
 ļ£
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))])
(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.
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
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.