physics420/580:computationalphysics - page not...

15
Physics 420/580: Computational Physics Final Exam Friday, December 13, 2013 / 14:00–17:00 / CCIS L1-207 Student’s Name: Instructions There are 22 questions. You should attempt all of them. For the multiple choice and long answer questions, simply mark your response on the test paper in the space provided. Please use a pen. And be sure to give plots meaningful labels. Good luck! 16 points multiple choice questions 1–16 12 long answer 17–18 22 programming 19–22 50 1

Upload: trinhthuy

Post on 08-May-2018

222 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

Physics 420/580: Computational Physics

Final Exam

Friday, December 13, 2013 / 14:00–17:00 / CCIS L1-207

Student’s Name:

Instructions

There are 22 questions. You should attempt all of them. For the multiple choice and long answer questions,simply mark your response on the test paper in the space provided. Please use a pen. And be sure to give plotsmeaningful labels.

Good luck!

16 points multiple choice questions 1–1612 long answer 17–1822 programming 19–22

50

1

Page 2: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

Multiple Choice Questions (16 points)

Answer by circling one of (a), (b), (c), etc. directly on the test paper—except for questions 2, 3, 4, and 10, whereyou should write the correct response into the blanks. Be sure that each selection is clear and unambiguous.

1. The sand pile cellular automata serves as a simple model of avalanche behaviour. Which of the followingstatements is incorrect.

(a) The dynamical steady state of this system is an example of self-organized criticality.(b) The distribution of avalanche sizes has a pure power law form.(c) There is a time scale governing the typical duration between avalanche events.(d) A single added grain can trigger a chain of cascading collapse events.

2. Consider the following command line session.

$ cat > test.cpp

#include <iostream>

using std::cout;

using std::endl;

int main()

{

double x = 9999999.4999999999;

float y = x;

double z = y;

cout.precision(20);

cout << x << endl;

cout << y << endl;

cout << z << endl;

return 0;

}

[ctrl-d]

$ make test

g++ test.cpp -o test

$ ./test

9999999.5

10000000

10000000

Whatwould the three lines of output be if—instead of having types double, float, and double, respectively—the variables x, y, and z were declared as float, double, and float? Write the output on the lines below.

Page 3: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

3. Match up the following three numerical differentiation schemes, approximating the solution to the ordinarydifferential equation x′(t) = F (x(t)),

(a) xn+1 = xn + F (xn)Δt

(b) xn+1 = xn +12

[

F (xn) + F (xn+1)]

Δt

(c) xn+1 = xn + F (xn +12F (xn)Δt)Δt

with their correct name:

( ) Runge-Kutta( ) Euler( ) Picard

4. In the molecule cyclopropane, three carbon atoms are linked together to form a ring. Suppose we want tosimulate this molecule as three classical point masses with a rigid-body constraint imposed on all pairwisedistances (fixing them at l). The corresponding Hamiltonian is

H =p212m

+p222m

+p232m

− �1,2[

(r1 − r2)2 − l2]2 − �2,3

[

(r2 − r3)2 − l2]2 − �3,1

[

(r3 − r1)2 − l2]2.

Match the following derivatives

(a) )H∕)p1 = p1∕m(b) −)H∕)r1 = 4�1,2

[

(r1 − r2)2 − l2]

(r1 − r2) − 4�3,1[

(r3 − r1)2 − l2]

(r3 − r1)

(c) −)H∕)�1,2 =[

(r1 − r2)2 − l2]2

with the appropriate equality:

( ) = ri( ) = p1( ) = 0

5. In question 4, the quantities �1,2, �2,3, and �3,1 are

(a) holonomic constraints(b) Langevin fields(c) Lagrange multipliers(d) holographic gauges

Page 4: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

6. The diagram on the left shows two planar trajectories, r1(t) = (x1(t), y1(t)) and r2(t) = (x2(t), y2(t)). Thediagram on the right shows the distance between them, d(t) = ‖r2(t) − r1(t)‖, plotted as a function oftime. (Note the log scale.)

x t

0.01

0.1

1 2 3 4 5

y d

Which statement is most correct?

(a) The Lyapunov exponent is negative.(b) The motion is regular rather than chaotic.(c) The resulting trajectories are highly dependent on the specification of initial conditions.(d) The Hamiltonian necessarily includes forcing and damping terms.

7. A long self-avoiding walk of fixed length is sampled via Monte Carlo using some combination of theupdate rules show below.

reptation move kink move pivot move

Which combination involves local updates only?

(a) reptation and kink(b) reptation and pivot(c) kink and pivot(d) pivot

Page 5: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

8. This program is meant to compute the first 20 Fibonacci numbers. It may or may not be correct.

int main()

{

int fib[20] = { 0, 1 };

for (size_t n = 20; n > 1; --n) fib[n] = fib[n-1] + fib[n-2];

for (size_t n = 0; n < 20; ++n) cout << "F" << n << " = " << fib[n] << endl;

return 0;

}

Which of the following is the output produced?

(a) F0 = 0

F1 = 1

F2 = 1

F3 = 1

F4 = 0

F5 = 0

(b) F0 = 0

F1 = 1

F2 = 1

F3 = 2

F4 = 3

F5 = 5

(c) F0 = 0

F1 = 1

F2 = 2

F3 = 3

F4 = 5

F5 = 8

9. In forward integrating the second-order ordinary differential equations of a Hamiltonian system (numer-ically, in discrete time steps), what feature would you want to preserve in order to satisfy Liouville’stheorem?

(a) space inversion(b) conservation of energy(c) symplectic symmetry(d) high Reynolds number

Page 6: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

10. The field u(x, t) is evaluated at a mesh of points u(n)i = u(i ⋅Δx, n ⋅Δt) in order to build a finite differenceapproximation to the partial differential equation

)u(x, t))t

= D)2u(x, t))x2

.

Match up three of the following four stencils

x

t

x

t

x

t

(a) (b)

(d)

x

t(c)

with these equations:

( ) u(n+1)i = (1 − 2s)u(n)i + s(u(n)i+1 + u(n)i−1)

( ) 2(1 + s)u(n+1)i − s(u(n+1)i−1 + u(n+1)i+1 ) = 2(1 − s)u(n)i + s(u(n)i−1 + u(n)i+1)

( ) u(n+1)i = s(u(n)i+1 + u(n)i−1 − 2u

(n)i ) + u

(n−1)i

( ) (1 + 2s)u(n+1)i − s(u(n+1)i+1 + u(n+1)i−1 ) = u(n)i

11. When s = DΔt∕(Δx)2 exceeds 1, which of the integration schemes depicted in question 10 becomenumerically unstable? Circle all that apply.

(a)(b)(c)(d)(e) none of them

Page 7: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

12. In conventional mathematical notation, the matrix

A =⎛

A1,1 A1,2 ⋯ A1,n⋮ ⋮Am,1 Am,2 ⋯ Am,n

has elements Ai,j indexed by row i = 1…m and column j = 1… n. Consider the special case where A isa square of dimensionN ×N and tridiagonal.For efficiency, we might want to store only thoseN +2(N −1) = 3N −2 elements that are nonzero. Let’spack them into a C array, ordering them by row—i.e.,

A1,1 |A1,2 |A2,1 |A2,2 |A2,3|A3,2 |A3,3 |A3,4 | … |AN−1,N−2 |AN−1,N−1 |AN−1,N |AN,N−1 |AN,N

—and then devise an indexing rule that works with C’s zero-based convention. Which is not a correctreplacement for ... in the following program?

#include <cassert>

#include <cstddef>

using std::size_t;

const size_t N = 8; double Adata[3*N-2];

double A(size_t i, size_t j)

{

assert(i < N and j < N);

if (i == j) return Adata[3*i];

else if (i < j) {

if (j-i > 1) return 0.0;

else return Adata[3*i + 1]; }

else if (i > j) {

if (i-j > 1) return 0.0;

else return ...; }

}

int main()

{

double sum = 0.0;

for (size_t i = 0; i < N; ++i)

for (size_t j = i+1; j < N; ++j)

sum += A(i,j);

return 0;

}

(a) Adata[3*j + 2]

(b) Adata[3*i - 1]

(c) Adata[3*j + 1]

(d) Adata[2*i + j]

Page 8: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

13. What does the code in question 12 actually compute? (Specifically, what value is held in sum when main

terminates.)

(a)∑

i,j Ai,j(b)

i<j Ai,j(c)

i≤j Ai,j(d)

i>j Ai,j(e)

i≥j Ai,j

The next three questions relate to the following Monte Carlo problem.

A confused and aimless passenger travels on the train network shown below.

(1) Toronto

(5) New York

(6) Philidelphia

(4) Boston

(2) Montréal

(3) Québec

Each day he moves from one city to the next according to the transition matrix

T =

0 a 0 0 0 0a′ 0 b c d 00 b′ 0 0 0 00 c′ 0 0 e 00 d′ 0 e′ 0 f0 0 0 0 f ′ 0

.

The elements Tij = Prob(j → i) denote the probability of going from city j to city i.

14. Which of the following is not a necessary condition for T to serve as a transition matrix?

(a) a′ = b = 1(b) c + e′ = 1(c) c′ + e = 1(d) e ≥ 0

Page 9: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

15. Suppose we use T to generate a Markov chain representing the passenger’s daily travel. We find that inthe long-time limit the passenger spends one third of her time in Montréal, Boston, and New York and avanishing fraction of time in the remaining cities. In other words, the steady-state distribution looks likethis:

limN→∞

�(N) = limN→∞

TN�(0) = �∗ =

01∕301∕31∕30

Which of the following inequalities is not consistent with this result?

(a) a′ < a(b) b′ < b(c) f ′ < f

16. What is the correct statement of detailed balance?

(a) �∗j Tji = �∗i Tij

(b) Tij�∗j = Tji�∗i

(c) Tij = Tji(d)

j Tij�∗j = �

∗i

(e) �∗j = �∗i

Page 10: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

Long Answer Questions (12 points)

17. (6 points) Consider the expression

F (x) = C[

f (x + a∕�) + �f (x + a∕�2) + f (x + a∕�3)].

(a) Find values of the coefficients �, , and C such that F (x) approaches the second derivative of f inthe limit of large �.

Page 11: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

(b) The discrepancy F (x) − f ′′(x) scales with what power of �?

(c) Explain why F (x) is a poor finite-difference approximation to f ′′(x).

Page 12: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

18. (6 points) Suppose we are given a two-species gas of classical particles evolving according to

mri = f ({rj}) + �({rj ,Rk})MRi = F ({Rj}) − �({rj ,Rk}).

The force laws f and F each arise from interactions within one species, and � encodes the interactionbetween species.

(a) Suppose the system is allowed to come into thermal equilibrium. Comment on the velocity distri-butions of the two particle species. Argue that the time step required for numerical simulation isdetermined by the lighter of the two.

Page 13: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

(b) Consider the extreme limit in which m ≪ M . Describe in words how we arrive at an effectiveone-species model of the form

MRi = F ({Rj}) − Ri.

Explain what each of the terms on the right-hand-side are meant to describe.

(c) What is the key property that sets the value of .

Page 14: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

Programming (22 points)

This section of the exam is to be completed on the computer. The program file is named logistic.cpp, andit should compile correctly with the provided makefile. When I ask you for a plot, please provide me with agnuplot script (named q19.gp or something equally obvious) that will generate it, or include an image file in aformat that I will have no trouble viewing (q19.pdf, q19.eps, q19.png). Please include meaningful labels.

You may want to organize your work into separate files logistic-q19.cpp, logistic-q20.cpp, etc. (and editthe makefile accordingly), so that incremental changes to your program are quarantined. But it’s up to you.

To start, download the Exam.tar.gz archive from the exam start page:

http://www.ualberta.ca/~kbeach/phys420_580_exam.html

Otherwise, retreive it with curl from the command line:

$ curl http://www.ualberta.ca/~kbeach/phys420_580_exam/src/Exam.tar.gz -O

Unpack the archive and append your own last name to the Exam directory. (Also include a first initial if you sharea last name with another student in the class.)

$ tar xzf Exam.tar.gz

$ mv Exam Exam_StudentLastName

$ cd Exam_StudentLastName

At the end of the exam, you should archive your work directory.

$ cd ..

$ tar czf Exam_StudentLastName.tar.gz Exam_StudentLastName

Email it to the instructor at [email protected].

N.B. Brute force solutions are fine. I don’t expect elegance in an hour and a half.

Page 15: Physics420/580:ComputationalPhysics - Page Not …kbeach/phys420_580_exam/docs/...10.Thefieldu.x;t/isevaluatedatameshofpointsu.n/ i =u.i x;n t/inordertobuildafinitedifference approximationtothepartialdifferentialequation)u.x;t/)t

The recurrence relation xn+1 = rxn(1−xn) is known as the logistic map. Given an initial condition x0 and a fixedvalue of the scaling parameter in the range 0 < r < 4, it produces a discrete time series of values 0 ≤ xn ≤ 1.For some choices of r, the behaviour is chaotic.

19. (4 points) I have provided a program file logistic.cpp that you can compile and run.

$ make

g++ -o logistic logistic.cpp -O -ansi -pedantic -Wall

$ ./logistic

usage: logistic (r-value > 0)

In its current version, the program takes a single command line argument and parses it as the parameter r.Modify the program so that it assigns x0 = 0.213 and runs the recurrence relation a few hundred times.

20. (4 points) Plot the sequence of points (n, xn) that result for the values r = 1∕2, 4∕3, and 5∕2. Verify thatthat they converge to 0, 0.25, and 0.6.

21. (4 points) Do the same for a value of r between 3 and 1 +√

6 and another between 1 +√

6 and 3.54409.Comment on the periodicity.

22. (10 points) Create a bifurcation diagram showing all the distinct values of xn that are obtained in thelarge-n limit over the range 5∕2 ≤ r ≤ 4.