

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
This is the Solved Exam of Computational Science which includes Matrix Manipulation Functions, Acceleration Due to Gravity, Normal Distribution, Normalised Expression, Exponential with Several Bins, Acceptable Code, Normal Distribution etc. Key important points are: Simultaneous Equations, Combination of Eigenvectors, Coefficients of Eigenvectors, Long-Term Population, Circle of Radius, Matrix Equation, Electron Number Density, Input Variable
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


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
(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.
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
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;