Upload
palison
View
214
Download
0
Embed Size (px)
Citation preview
8/14/2019 Mathematica Final - What I could do
1/18
Physics/Chem 229& 100 Final Exam 2009Due Monday, Dec 14 at midnightOpen book, but no discussion with anyone except me. You may use any packages that seemhelpful. Provide clear commentary in text cells so that I can follow your reasoning.
grads do all problemsUndergrads get extra credit for problems marked (grads)Name: Peter D. Alison
1a). Are the vectors v1={1, -2, 3, 4} , v2= {-2, 0, 3, 6}, v3= {4, -4, 3, 2} linearly independent? Why or why not?
v1 1, 2, 3, 4; v2 2, 0, 3, 6; v3 4, 4, 3, 2;
We must make a linear combination of these vectors and see if there is a nontrivial
solution. If there is a nontrivial solution then these vectors are linearly dependent.
Array, 3
1, 2, 3sysofeqs Table1 v1i 2 v2i 3 v3i 0, i, 1, 4
1 2 2 4 3 0, 2 1 4 3 0,3 1 3 2 3 3 0, 4 1 6 2 2 3 0
Solvesysofeqs, Array, 3
Solve::svars : Equations ma y not give solutions for all "solve" variables.
1 2 3, 2 3
Since we have a nontrivial solution, where we can vary only [3] (nontrivial solu-
tion) for this system of equations based on our vectors, these vectors are linearly
dependent
mat, rhs EqToMatsysofeqs, Array, 3
1, 2, 4, 2, 0, 4, 3, 3, 3, 4, 6, 2, 0, 0, 0, 0MatrixFormmat
1 2 4
2 0 4
3 3 3
4 6 2
MatrixFormRowReducemat
1 0 2
0 1 1
0 0 0
0 0 0
This is another way to show that the vector are linearly dependent, using a matrix
method instead of solving a system.
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
2/18
b) Find a set of vectors that span the hyperplane w - 2.3 x- 2 y- 3.4z == 6
hyperplane 2.3, 2, 3.4, 1.x, y, z, w 6
w 2.3x 2 y 3.4 z 6
NullSpace2.3, 2, 3.4, 1NullSpace ::matrix : Argum ent 2 . 3 , 2 , 3 . 4 , 1 a t p o si t i o n 1 i s n o t a n o ne m p t y r e c t a n g u l a r m a t r i x .
NullSpace2.3, 2, 3.4, 1
2. Find the solution to the equations2x+3y+2z=105x-2y+7z=0
which has minimum length x2 y2 z2 .
The plane equations are our constraints and the length function is what we want to
minimize.
planes
ContourPlot3D2 x 3 y 2 z 10, 5 x 2 y 7 z 0, x, 10, 10, y, 10, 10, z, 10, 10
10
5
0
5
1010
5
0
5
10
10
5
0
5
10
constraint1 2 x 3 y 2 z 10
10 2 x 3 y 2 z
constraint2 5 x 2 y 7 z
5 x 2 y 7 z
2 Final09.nb
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
3/18
length x2 y2 z2
x2 y2 z2
laux length 1 constraint1 2 constraint2
x2 y2 z2 10 2 x 3 y 2 z 1 5 x 2 y 7 z 2auxconds ThreadDlaux, x, Dlaux, y, Dlaux, z 0
xx2 y2 z2
2 1 5 2 0,y
x2 y2 z2
3 1 2 2 0,z
x2 y2 z2
2 1 7 2 0
mineqs Joinauxconds, constraint1 0, constraint2 0
xx2 y2 z2
2 1 5 2 0,y
x2 y2 z2
3 1 2 2 0,
z
x2 y2 z2
2 1 7 2 0, 10 2 x 3 y 2 z 0, 5 x 2 y 7 z 0
solmin Solvemineqs, x, y, z, 1, 2 Flatten
1 13167
, 2 3
2171
, x 110
167, y
450
167, z
50
167
xyz x, y, z . solmin
110167
,450
167,
50
167
xyz N
0.658683, 2.69461, 0.299401
Final09.nb 3
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
4/18
Showplanes, Graphics3D Red, Spherexyz, 0.5
10
5
0
5
10
5
0
5
10
10
5
0
5
10
This plot shows the geometric interpretation of the problem we just solved. The inter-
section of these two planes is a line, and we found the point of that line that is
closest to the origin. We can see the red sphere of the intersection line.
3. Find all solutions to z7 2 z5 3 z2 5 z 1 0 Make a plot which shows the location of the roots in the
complex plane.We can use NSolve to find all seven roots of this polynomial.
zsol NSolvez7 2 z5 3 z2 5 z 1 0, zz 0.976459 0.860662 , z 0.976459 0.860662 ,z 0.180397, z 0.141399 1.6738 , z 0.141399 1.6738 ,z 0.925258 0.550911 , z 0.925258 0.550911
Lengthzsol
7
Here are our roots to the polynomial and we can see that there are seven of them. In
fact, the computer has counted seven as well.
zs z . zsol
0.976459 0.860662 , 0.976459 0.860662 , 0.180397,0.141399 1.6738 , 0.141399 1.6738 , 0.925258 0.550911 , 0.925258 0.550911
Here are all the solutions in the form of a list.
4 Final09.nb
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
5/18
TransposeRezs, Imzs
0.976459, 0.860662, 0.976459, 0.860662, 0.180397, 0,0.141399, 1.6738, 0.141399, 1.6738, 0.925258, 0.550911, 0.925258, 0.550911
Here are our solutions as coordinates on the complex plane.
ListPlotTransposeRezs, Imzs,PlotStyle PointSize0.025, AxesLabel "Re", "Im"
1.0 0.5 0.5Re
1.5
1.0
0.5
0.5
1.0
1.5
Im
Here are our root plotted on the complex plane.
4. Calculate the value of the integral Int 02 Sin 2
53 Cos using residues (use of Residues[...] is OK).
Specify the contour you are using by drawing a sketch. Explain your reasoning.
We start with trig form and convert the integrand to z form.
f Sin2
5 3 CosSin2
5 3 Cosf TrigToExpf
2
4 5 32
fz f . z, 1 z
1z
z2
4 5 32 1z zintz Simplifyfz z
1 z222 z2 3 10 z 3 z2
We are looking for the instances where the denominator of intz is equal to zero.
Final09.nb 5
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
6/18
solz Solve1 intz 0, z
z 3, z 13, z 0, z 0
Here are the locations of the poles.
pole1, pole2, pole3, pole4 z . solz
3, 13, 0, 0
We want the residues inside the unit circle. That will 1
3and zero.
res2 Residueintz, z, pole2
4
9
res3 Residueintz, z, pole3
5
9
The sum of residues inside the unit circle.
sumres res2 res3
9
Using our residue theorem where the integral is equal to the sum of the residues
inside the unit circle multiplied by 2 .
2 sumres
2
9
IntegrateSin2
5 3 Cos, , 0, 2 , PrincipalValue True
2
9
We use the principal value method to verify the sum of residues method, and we get
the same answer.
6 Final09.nb
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
7/18
5. Two identical masses are attached to three springs between two fixed walls, as shown in the figurebelow.
m m
k1 k2 k1
a) Construct the Lagrangian , and set up the equations of motion for this system
VariationalMethods`
CleartThe potential energy has three terms, one for each spring.
potentialEnergy 1
2k1 x1t2
1
2k2 x1t x2t2
1
2k1 x2t2
1
2k1 x1t2 1
2k2 x1t x2t2 1
2k1x2t2
We are assuming one - dimensional motion.
kineticEnergy 1
2m x1' t2
1
2m x2' t 2
1
2m x1
t2 12m x2
t2
Lagrangian kineticEnergy potentialEnergy
1
2k1 x1t2 1
2k2 x1t x2t2 1
2k1x2t2 1
2m x1
t2 12m x2
t2
euleqs EulerEquationsLagrangian, x1t, x2t, t
k1 k2 x1t k2 x2t m x1t 0, k2 x1t k1 k2 x2t m x2t 0Here are the equations of motion for each of the masses.
b) Calculate the normal mode frequencies for the vibrations of this system.
scndrv Solveeuleqs, x1''t, x2''t FullSimplify Apart Flatten
x1t k1 k2 x1tm
k2 x2t
m, x2
t k2 x1tm
k1 k2 x2t
m
Final09.nb 7
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
8/18
Then we construct the matrix out of the coefficients of equations of motion. Then
eigenvalues of the matrix are the 2, the normal frequencies squared.
modesmat
k1k2m
k2
m
k2
m
k1k2m
k1 k2m
, k2
m, k2
m,k1 k2
m
normalmodes Eigenvaluesmodesmat
k1m,k1 2 k2
m
Sqrtnormalmodes
k1m
,k1 2 k2
m
Here are the normal mode frequencies for the vibrations of this system.
6. Consider the differential equation y'' [x]/5 - x2 y' x- y[x]=0a) Find a power series approximation to the initial value problem y[0]=3 , y'[0]=1/2 .
We can easily find the power series approximation, with the handy powerss function
provided in the handbook.
ode y''x 5 x2 y'x yx
yx x2 yx yx5
pss powerssode, y, x, 12, 0, False
1 5 x2
225 x4
245 x5
425 x6
144325x7
5044625 x8
80642125 x9
1814413675 x10
4838485375 x11
399168323375 x12
6386688a0
x 5 x3
65 x4
125 x5
2435 x6
7225 x7
112275 x8
20165275x9
241923425x10
362884525 x11
76032106625 x12
1368576a1
8 Final09.nb
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
9/18
powerssde_, yv_, xv_, deg_, pt_, verbose_ :Blockps, subps, eqs, params, vars, ss, sv, order, dexp ,dexp de . xx_ yy_ xx yy;order MaxCasesdexp, q_. Derivativen_x_y_ n, Infinity; the order of de
ps i0
deg
ai xv pti
; the trial solution vars Tableai, i, order, deg; a0, a1,.. aorder1 are parameters
params Tableai, i, 0, order 1;subps dexp . yv Functionxv, Evaluateps; plug it into the de subps NormalSeriessubps, xv, pt, deg;eqs TableCoefficientsubps, xv pt, i 0, i, 0, deg order; set each coefficient0 Ifverbose, Print"DE ", de, " order ", order,
"\nTrial solution ", ps, "\nplug in power series:\n",
subps, "\neqs for coefficients ", TableFormeqs;Print"\nparams ", params, "\nvariables ", vars;
ss ps . FirstSolveeqs, vars;sv TableMapFactor, ss . ai 1 . Threadparams 0, i, 0, order 1;sv.params
iniconds pss . x 0 3, Dpss, x . x 0
1
2
a0 3, a1 12
asol Solveiniconds, a0, a1 Flatten
a0 3, a1 12
Apparently the initial conditions solve themselves for the parameters a[0] and a[1].
pss . asol
3 1 5 x2
225 x4
245 x5
425 x6
144325x7
5044625x8
80642125 x9
1814413675 x10
4838485375 x11
399168323375 x12
6386688
1
2x
5 x3
65 x4
125 x5
2435 x6
7225 x7
112275x8
20165275 x9
241923425 x10
362884525x11
76032106625 x12
1368576
b) Construct a plot of the solution to the boundary value problem y[0]=1, y[2]=1 (Although you could use ashooting method, there is an easier way.)
odesol NDSolveode 0, y0 1, y2 1, yx, x, 0, 2 Flatten
y
x
InterpolatingFunction
0., 2.
,
x
Final09.nb 9
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
10/18
Plotyx . odesol, x, 0, 2, PlotStyle Thick, Red, AxesLabel "x", "yx"
0.5 1.0 1.5 2.0x
0.4
0.6
0.8
1.0
yx
c) what are the possible types of asymptotic behavior as x -> for solutions of this equation?
Needs
"MMHTools`DETools`"
asymptotic code was executed in the handbook.
yz ChangeVariableode, x 1 z, y, y, x, z
yz yz 25z3 yz 1
5z4 yz
ClassifyODEyz, y, z, 0, False
irregular singular point
asymptoticode, y, x, 3, False
Power::infy : Infinite exp ress ion1
0e n c o u n t e r e d .
this de does not have an
irregular singular point at Infinity; use frobenius
5 x3
3
x2, 1
7
30 x3
1
2 x21
x, 1, 1 1
6 x3
1
2 x21
x
7. Gravitational stability of 3 masses. Consider three objects of unit mass which are constrained to move
in a plane and interact via an attractive inverse square force law with a potential V(r)= -1
r, where r is the
distance between the masses. The initial condition is that all the masses are stationary, and mass #1 is at{0, 0} , mass#2 is at {0,-1} and mass#3 is at {3,0} .a) write the Lagrangian for this system.
VectorAnalysis`
ClearV
Vr1_, 1_, r2_, 2_ : 1
r12 r22 2 r1 r2 Cos1 2
10 Final09.nb
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
11/18
xypos 0, 0, 0, 1, 3, 0
0, 0, 0, 1, 3, 0
rpos xypos . x_, y_ x2 y2 , Ifx 0 && y 0, 0, ArcTanEvaluatex, y
0, 0, 1,
2 , 3, 0potEn Vr1t, 1t, r2t, 2t
Vr2t, 2t, r3t, 3t Vr3t, 3t, r1t, 1t
1
r1t2 2 Cos1t 2t r1t r2t r2t2
1
r1t2 2 Cos1t 3t r1t r3t r3t2
1
r2t2
2 Cos
2t
3t r2t r3t
r3t
2
The potential depends on the distance and in this case using the polar coordinates
distance formula
kinEn 1
2r1't2
1
21't2
1
2r2't2
1
22't2
1
2r3't2
1
23't2
1
2r1
t2 12r2
t2 12r3
t2 12
1t2 1
22
t2 12
3t2
The kinetic energy for each mass has two terms, one for r coordinate and one for the
coordinate.
lagrange kinEn potEn
1
r1t2 2 Cos1t 2t r1t r2t r2t2
1
r1t2 2 Cos1t 3t r1t r3t r3t2
1
r2t2 2 Cos2t 3t r2t r3t r3t21
2r1
t2
1
2r2
t2 12r3
t2 12
1t2 1
22
t2 12
3t2
Final09.nb 11
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
12/18
b) Write the equations of motion. What is the total energy of the system?
eqsofmotion
EulerEquationslagrange, r1t, r2t, r3t, 1t, 2t, 3t, t FullSimplify
r1t Cos1t 2t r2t
r1t2 2 Cos1t 2t r1t r2t r2t232 r1t Cos1t 3t r3t
r1t2 2 Cos1t 3t r1t r3t r3t232 r1
t,
Cos1t 2t r1t r2tr1t2 2 Cos1t 2t r1t r2t r2t232
r2t Cos2t 3t r3tr2t2 2 Cos2t 3t r2t r3t r3t232
r2t,
Cos1t 3t r1t r3t
r1
t
2 2 Cos
1
t
3
t
r1
t
r3
t
r3
t
2
32
Cos2t 3t r2t r3tr2t2 2 Cos2t 3t r2t r3t r3t232
r3t,
r1t r2t Sin1t 2tr1t2 2 Cos1t 2t r1t r2t r2t232
r3t Sin1t 3tr1t2 2 Cos1t 3t r1t r3t r3t232
1t,
r1t r2t Sin1t 2tr1t2 2 Cos1t 2t r1t r2t r2t232
r2t r3t Sin2t 3tr2t2 2 Cos2t 3t r2t r3t r3t232
2t,
r3t r1t Sin1t 3tr1t2 2 Cos1t 3t r1t r3t r3t232
r2t Sin2t 3tr2t2 2 Cos2t 3t r2t r3t r3t232
3t
The total energy of the system is initially potential. Initial kinetic energy is
zero, so we can find the initial potential energy as the total energy of the system.
potEn0 Vrpos1, 1, rpos1, 2, rpos2, 1, rpos2, 2 Vrpos2, 1, rpos2, 2, rpos3, 1, rpos3, 2 Vrpos3, 1, rpos3, 2, rpos1, 1, rpos1, 2
4
3
1
10
12 Final09.nb
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
13/18
c) Solve the equations for the given initial conditions and make an animation of the motion. (Watch out forextra curly brackets.) Use different colored dots to represent the objects. Play the animation at 20frames/second. An interesting question that you are invited to speculate on is : will the particles everbecome separated by an infinite distance?
Our initial conditions are the given inital points and zero velocities.
initialconditions r10 rpos1, 1, 10 rpos1, 2,r1'0 0, 1'0 0, r20 rpos2, 1, 20 rpos2, 2, r2'0 0,2'0 0, r30 rpos3, 1, 30 rpos3, 2, r3'0 0, 3'0 0
r10 0, 10 0, r10 0, 10 0, r20 1, 20 2,
r20 0, 20 0, r30 3, 30 0, r30 0, 30 0
numsol NDSolveeqsofmotion, initialconditions,r1t, 1t, r2t, 2t, r3t, 3t, t, 0, 10, MaxSteps 50000 Flatten
N D So l v e : : m x st : M a x i m u m n u m b e r o f 5 0 0 0 0 st e p s r e a c h e d a t t h e p o i n t t 6 . 6 6 2 7 0 5 7 2 5 5 5 2 3 5 8 5 ` .
r1t InterpolatingFunction0., 6.66271, t,1t InterpolatingFunction0., 6.66271, t,r2t InterpolatingFunction0., 6.66271, t,2t InterpolatingFunction0., 6.66271, t,r3t InterpolatingFunction0., 6.66271, t,3t InterpolatingFunction0., 6.66271, t
rtoxy r_, _ r Cos, r Sin
r_, _ r Cos, r Sintraj Table
GraphicsGreen, Diskr1t . numsol1, 1t . numsol2 . rtoxy, 0.2,Purple, Diskr2t . numsol3, 2t . numsol4 . rtoxy, 0.2,Black, Diskr3t . numsol5, 3t . numsol6 . rtoxy, 0.2,
PlotRange 1, 10, 3, 3, t, 0, 6.6, 0.01;ListAnimatetraj, 20
Seeing how the black dot leaves the screen at the end of the animation, the particle
might be able to be separated by an infinite distance.
Final09.nb 13
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
14/18
8. (grads) An electron is confined to a spherical cavity of radius R. ( This is actually a realistic model for
electrons in some liquids). The equation for its stationary energy states is 2
2 m2 E . The wave
function must vanish at the boundary and be finite at the origin.a) Using dimensional reasoning , predict the dependence of the ground state energy on the radius of the
cavity.
Needs"Units`"Needs"PhysicalConstants`"Needs"MMHTools`DimTools`"
The symbols c, kB, , g, G, me, amu, Me, Ms, Na, 0, 0, e, , Rgashave been assigned SI unit specifiers
basisunits Meter, Kilogram, Second, Kelvin, Coulomb
Meter, Kilogram, Second, Kelvin, Coulombelectronparameters R Meter, p Kilogram Meter Second, ToSymbolsUnits ReduceUnits
Meter R, pKilogram Meter
Second,
Kilogram Meter2
Second
Meter R, m Kilogram,Kilogram Meter2
Second
Meter R, Kilogram m, Kilogram Meter2
Second
dimanalelectronparameters, basisunits, Joule ReduceUnits
Fi rst : : n o r m a l : N o n a t o m i c e x p r e ss i o n e x p e c t e d a t p o si t i o n 1 i n Fir st1 .
First1, R
b) For the case of no angular dependence, find the lowest 3 energy levels and the corresponding radialwave functions. Normalize the wave functions and plot them ( let R->1). Do this problem analytically, notnumerically.
VectorAnalysis`
SetCoordinatesSphericalr, ,
Sphericalr, , Laplacianr
Csc
2 r Sin
r
r2 Sin
r
r2
14 Final09.nb
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
15/18
8/14/2019 Mathematica Final - What I could do
16/18
9. A potential is zero for Abs[x]>1 and for Abs[x]
8/14/2019 Mathematica Final - What I could do
17/18
b) estimate the value of V0 which leads to exactly 2 bound states.
10.Buffon needle problem. Consider a sheet of lined paper with parallel lines one unit apart. Drop a stickone unit in length at random where random means random orientation angle and random position. Do thismany times. What is the probability that the stick does not intersect a line? Answer this question with asimulation. Write a function called Buffon[ntry_,maxgraph_] which will generate ntry sticks Graphwhose center position is a random number between 0 and 1, and whose orientation angle is a randomnumber between 0 and 2 . Display a picture of two red parallel lines one unit apart, and the first
maxgraph black line segments (the sticks); plotting them all leads to a messy black porcupine, so keep
maxgraph around 50 or 70. Keep track of the number of line segments which cross either of the parallel
lines. Run the simulation with ntry=5000 or so times and estimate the probabilities of intersection and non-intersection.
Clear"Global`"
Buffonntry_, maxgraph_ :Blockhs, points, boundaries, numcross, ys, yscross, probcross, probnocross,hs TableRandomReal, RandomReal2 , ntry;
points hs . h_, _ 1 2 Cos, h 1 2 Sin, 1 2 Cos, h 1 2 Sin;ys points . x1_, y1_, x2_, y2_ y1, y2 Flatten; yscross ;DoIfysi 1 ysi 0, AppendToyscross, ysi, i, Lengthys;numcross Lengthyscross; probcross numcross ntry;
probnocross 1 probcross; Printprobcross; Printprobnocross; boundaries GraphicsThick, Red, Line3, 1, 3, 1, Thick, Red, Line3, 0, 3, 0;
Showboundaries, GraphicsTableLinepointsi, i, maxgraph Buffon10000, 50
1583
2500
917
2500
Our output is the probability of crossing the lines, the probability of not cross the
lines, and a picture of the first fifty trials.
Buffon2ntry_ :Blockhs, points, boundaries, numcross, ys, yscross, probcross, probnocross,hs TableRandomReal, RandomReal2 , ntry;
points hs
.
h_, _
1
2 Cos
, h 1
2 Sin
,
1
2 Cos
, h 1
2 Sin
;
ys points . x1_, y1_, x2_, y2_ y1, y2 Flatten; yscross ;DoIfysi 1 ysi 0, AppendToyscross, ysi, i, Lengthys;numcross Lengthyscross; probcross numcross ntry;
probnocross 1 probcross; Returnprobcross
Adjusting the Buffon program to return only the probability of crossing the lines, I
can take the mean of a large number of 10000 trials sets.
Final09.nb 17
Printed by Mathematica for Students
8/14/2019 Mathematica Final - What I could do
18/18
MeanTableBuffon210000, 10000
509321
800000
159173
250000
N
0.636692
509321
800000 N
0.636651
And I can conclude that the probability of crossing the lines is 0.636651 or 63.6651
%
100 63.6651
36.3349
18 Final09.nb
Printed by Mathematica for Students