Escolar Documentos
Profissional Documentos
Cultura Documentos
ODEs
Basic tool is “DSolve”
Note that in DSolve the dependent variable (usually y below) must be written y[x] or
y’[x] (for the derivative) or y’’[x] (for the second derivative) etc.. You cannot write just “y”.
Mathematica needs to know that y is dependent.
Also don’t forget to use a double equals sign: ==
::y@xD ® ãã TanA E
>>
C@1D x
2
::y@xD ® ã 3 TanA E
>>
x
2
3 TanB F
x
y@xD=ã 2
40
30
20
10
x
3Π Π Π Π Π 3Π
-Π - - - Π
4 2 4 4 2 4
3 TanB F
x
y@xD=ã 2
105
1000
10
0.100
0.001
10-5
x
3Π Π Π Π Π 3Π
- - - 0 Π
4 2 4 4 2 4
Note that this solution differs from that derived in class only in that the constant C[1] here corresponds
to (2+y(0)) in the expresssion in lecture notes.
This comparison is what Boas calls “reconciling”.
y0 =-1
2
y0 =0
1 y0 =1
x
Π 3Π
Π 2
2Π
2
-1
Slope plot
Here is the “slope plot”, with the slope arrows normalized to unit length.
Note that the normalized slope vector is given by {1, y’ } / Sqrt[1+(y’)^2].
4 RevisedODE1.nb
slopeplot = VectorPlot@
81, Sin@2 xD - y Cos@xD< Sqrt@1 + HSin@2 xD - y Cos@xDL ^ 2D, 8x, 0, 7<, 8y, - 1.5, 4.5<D
5
-1
-2
0 2 4 6
Overlaying the solutions on the slope plot shows how the slope plot allows you to visualize the solutions
by following arrows (head to tail to head to tail etc.):
Show@slopeplot, solnplotD
-1
0 1 2 3 4 5 6 7
RevisedODE1.nb 5
Stream Plot
Here’s an alternative, using “StreamPlot[]” in which Mathematica does the
work of connecting the arrows “head to tail” and curving them so that one can see the “flows” (which are
the solutions to the original differential equation).
Note that in this case one does not need to normalize the slope vectors
streamplot = StreamPlot@81, Sin@2 xD - y Cos@xD<, 8x, 0, 7<, 8y, - 1.5, 4.5<D
5
-1
0 2 4 6
Overlaying shows that the head-to-tail arrows really do map out the solutions
6 RevisedODE1.nb
Show@streamplot, solnplotD
5
-1
0 2 4 6
Contour plot
Here is another way of showing the family of solutions using a contour plot
First rewrite the solution so that only the constant of integration (here y(0)) is on the RHS.
Then put the LHS into contour plot.
The labels on the lines give the values of y(0).
RevisedODE1.nb 7
10 8
4 4 4
8
6
3 6
2 0 2
0 -2
-4 -2
-1
-6
-2 -4
0 1 2 3 4 5 6 7
10 8
4 4 4
8
6
3 6
2 0 2
0 -2
-4 -2
-1
-6
-2 -4
0 1 2 3 4 5 6 7
2
2.19
2.92 y0 =-1
0 y0 =0
1.46
1.46
1
y0 =1
0 -2.19
-0.73
-4.38 -2.19
-1
-5.11
-5.84
-3.65
-6.57
-2 -2.92 -3.65 -1.46 -1.46 -2.92-4.38
0 1 2 3 4 5 6 7
Orthogonal curves
These are curves orthogonal to the solutions at all points.
In some cases one can solve analytically for these (as in the examples in
Boas and in one of the HW problems), but in the present case one cannot.
However one can visualize these curves using StreamPlot[] without having an explicit solution.
Note that (as discussed in class lecture notes) the slope of the orthogonal curve at a given point {x,y} is
given by -1/(slope of solution).
The directions of the arrows in the following plot should be ignored.
RevisedODE1.nb 9
-2
0 2 4 6
Superimposing on the family of solution curves, one sees that the orthogonal trajectories can be thought
of as paths of steepest descent over the “landscape” of the solutions.
Show@curvefamily, orthogcurvesD
5
10 8
4 4 4
8
6
3 6
2 0 2
0 -2
-4 -2
-1
-6
-2 -4
0 1 2 3 4 5 6 7
Sec. 8.4 #5
First simply solve and look at solutions:
DSolve@y '@xD Hx - y@xDL + y@xD + x + 1 0, y@xD, xD FullSimplify
Rewrite solutions without pesky i’s and minus signs inside square-roots.
Integration constants are chosen so that yplus[0]=yplus0 and yminus[0]=-yminus0
yplus@x_, yplus0_D := x + Sqrt@2 Hx ^ 2 - xL + yplus0 ^ 2D;
yminus@x_, yminus0_D := x - Sqrt@2 Hx ^ 2 - xL + yminus0 ^ 2D
20
y0 =10
10
y0 =-10
x
2 4 6 8 10
-10
Now make use of fact that ODE is exact, so the solution can be written as F(x,y)=constant, where F is
given by:
f845@x_, y_D := x y - y ^ 2 2 + x ^ 2 2 + x
RevisedODE1.nb 11
-150
15
-100
10
100
5
y
50
0 0
-5
-50
-10
0 2 4 6 8 10
x
To be clear: contour lines are solutions to our ODE, and you can see that two of the contours match the
plots above.
Sec 8.5 #7
Simple second order linear with constant coeffs and homogeneous.
Answer agrees with lecture notes.
DSolve@y ''@xD - 5 y '@xD + 6 y@xD 0, y@xD, xD
99y@xD ® ã2 x C@1D + ã3 x C@2D==
1.0
0.8
0.6
0.4
0.2
-2 -1 1 2
Note: The “Exclusions ® None” option tells Mathematica to always connect the line, even at the disconti-
nuities at x=+/-1
Here’s the Fourier transform
The “FourierParameters” command sets parameters to match our conventions
ftff@alp_D = FourierTransform@ff@xD, x, alp, FourierParameters ® 8- 1, - 1<D
Sin@alpD
alp Π
The format for FourierTransform[ ] is FourierTransform[function you want to transform, initial variable
(eg. time), transformed variable (eg. frequency)]. The “FourierParameters®{a,b}” fit into the transforma-
b¤
à
¥
fHtL ei b Ω t dt.
H2 ΠL
tion as:
1-a -¥
RevisedODE1.nb 13
0.3
0.2
0.1
-10 -5 5 10
PlotAAbs@ftff@alpDD2 , 8alp, - 3.5 Pi, 3.5 Pi<, PlotStyle ® 8Thick<, PlotRange ® AllE
0.10
0.08
0.06
0.04
0.02
-10 -5 5 10
This may (or may not) look familiar as the intensity pattern resulting from a single slit with incident plane
waves. This should make sense as a slit’s can be discribed as a step funciton and Fraunhofer diffraction
tells us the amplitude of a diffracted wave is the Forier transform of the aperture. You will learn more
about this is E&M.
Solve directly:
14 RevisedODE1.nb
soln = DSolve@8y ''@xD + 3 y '@xD + 2 y@xD ff@xD, y@- 1D 0, y '@- 1D 0<, y@xD, xD
0 x £ -1
::y@xD ® H- 1 + ã1+x L2 - 1 < x £ 1 >>
1
2
ã-2-2 x
H- 1 + ã2 L H- 1 - ã1+x L
1
2
ã-2-2 x ã2 +2 True
Oscillator is pushed to one side, and continues moving after the push stops (at x=1) but then turns
around and damps.
plotsoln = Plot@y@xD . soln, 8x, - 2, 6<, PlotStyle ® ThickD
0.4
0.3
0.2
0.1
-2 2 4 6
This is the function whose inverse Fourier transform gives the solution to the differential equation (as
discussed in lecture notes):
yft@alp_D = HSin@alpD HPi alpLL 1 HHI alp + 2L HI alp + 1LL
Sin@alpD
H1 + ä alpL H2 + ä alpL alp Π
0.3
0.2
0.1
-2 2 4 6
0.3
0.2
0.1
-2 2 4 6