Docsity

Simultaneous Equations - Computational Science - Solved Exam, Exams of Computational Physics

Toggle sidebar
bg1
COSC1001/1901 (Semester Two, 2009) Exam Solutions and Marking Scheme
Computational Science in MATLAB
COSC1001 (Normal) & COSC1901 (Advanced)
Exam Solutions and Marking Scheme
1. (a) (2 marks) count counts the number of experiments where x==1, which is his home. So
the probability is 1-0.2476=0.7524.
(b) (2 marks) 0.2453, 0.2510 etc. It would not be reasonable to expect 0.16.
(c) (3 marks) The answer follows from an argument like:
P(round(a+rand) == 1) = P(a+rand >0.5) (1)
=P(rand >0.5−a) (2)
= 0.5 + a(3)
(d) (3 marks) a= 0.3
x = x + 2*round(0.3+rand) - 1
2. (a) (2 marks) αand βare the survival rates, and a maximum of 100% of the population
can survive at each generation.
(b) (2 marks) A = [0 1 0.5; 0.8 0 0; 0 0.5 0];
(c) (4 marks) The ratio children:adults:retirees should be 0.7454:0.5963:0.2981, and the
population will remain stable over time. This is because the eigenvalue with largest
magnitude is 1.0. Any initial starting population can be decomposed into a linear
combination of the three eigenvectors, and the coefficients of eigenvectors 2 and 3 will
gradually decay over time, leaving only the first eigenvector.
(d) (4 marks) If the long-term population is stable, then we must have:
(A−I)e= 0
for some eigenvector e=e1, e2, e3. This reduces to three simultaneous equations:
−e1+r2e2+r3e3= 0 (4)
αe1=e2(5)
βe2=e3(6)
This is trivial to solve:
e1(−1 + αr2+αβr3) = 0,
and the identity follows.
3. (a) (3 marks) Begin with 104sets of 2 random numbers between -1 and 1. The fraction of
these numbers that land within the circle of radius 1 is the ratio of the area of the unit
circle (i.e. π) to the area of the square defined by −1< x < 1 and −1< y < 1 (i.e. 4).
(b) (2 marks) x=2*rand(10000,1)-1
(c) (4 marks)
1
pf3

Partial preview of the text

Download Simultaneous Equations - Computational Science - Solved Exam and more Exams Computational Physics in PDF only on Docsity!

Computational Science in MATLAB

COSC1001 (Normal) & COSC1901 (Advanced)

Exam Solutions and Marking Scheme

  1. (a) (2 marks) count counts the number of experiments where x==1, which is his home. So the probability is 1-0.2476=0.7524. (b) (2 marks) 0.2453, 0.2510 etc. It would not be reasonable to expect 0.16. (c) (3 marks) The answer follows from an argument like:

P (round(a + rand) == 1 ) = P (a + rand > 0. 5 ) (1) = P (rand > 0. 5 − a) (2) = 0 .5 + a (3)

(d) (3 marks) a = 0. 3 x = x + 2*round(0.3+rand) - 1

  1. (a) (2 marks) α and β are the survival rates, and a maximum of 100% of the population can survive at each generation. (b) (2 marks) A = [0 1 0.5; 0.8 0 0; 0 0.5 0]; (c) (4 marks) The ratio children:adults:retirees should be 0.7454:0.5963:0.2981, and the population will remain stable over time. This is because the eigenvalue with largest magnitude is 1.0. Any initial starting population can be decomposed into a linear combination of the three eigenvectors, and the coefficients of eigenvectors 2 and 3 will gradually decay over time, leaving only the first eigenvector. (d) (4 marks) If the long-term population is stable, then we must have:

(A − I)e = 0

for some eigenvector e = e 1 , e 2 , e 3. This reduces to three simultaneous equations:

−e 1 + r 2 e 2 + r 3 e 3 = 0 (4) αe 1 = e 2 (5) βe 2 = e 3 (6)

This is trivial to solve:

e 1 (−1 + αr 2 + αβr 3 ) = 0,

and the identity follows.

  1. (a) (3 marks) Begin with 10^4 sets of 2 random numbers between -1 and 1. The fraction of these numbers that land within the circle of radius 1 is the ratio of the area of the unit circle (i.e. π) to the area of the square defined by − 1 < x < 1 and − 1 < y < 1 (i.e. 4). (b) (2 marks) x=2*rand(10000,1)- (c) (4 marks)

function pi_est=estimatepi(n) %This function computes a monte-carlo estimate for pi x=rand(n,1); y=rand(n,1); pi_est=mean(x.^2+y.^2 < 1)*4; end (d) i. (2 marks) 5 (as a = [-1 1 3 5 7]) ii. (2 marks) 7 7 iii. (2 marks) 8 9

  1. (a) (4 marks) The 4 equations are as follows, with the variables we are solving for being nH, nHe, nH+ and nHe+.

nH − fH (T )nenH+ = 0 (7) nHe − fHe(T )nenHe+ = 0 (8) nH + nH+ − 10 nHe − 10 nHe+ = 0 (9) nH+ + nHe+ = ne (10)

These obviously have to be written as a matrix trivially for full marks. The students also need a little inspiration to realize that the electron number density can not be part of the linear system, and needs to be considered an input variable in order to write a matrix equation (actually, that part of the full problem is non-linear). (b) (4 marks) Something like the folloing, which was actually designed for 2 ionization states of He...

function ns=saha(n_e, T) %This function returns a vector nH, nHplus, nHe and nHeplus m = zeros(5); m(1,1:2)=[1 -fH(T)n_e]; m(2,3:4)=[1 -fHe(T)n_e]; m(3,:)=[1 1 -0.1 -0.1]; m(4,:)=[0 1 0 1]; b=[0 0 0 0 n_e]’; ns=m/b; end

(c) (2 marks) function f=myfunc(xyz) x=xyz(1); y=xyz(2); z=xyz(3); f = cos(x+y) + (sin(x+z)).^2; end (d) (2 marks) function xyz=randomsphere xyz=2.*rand(3,1)-1;