0% found this document useful (0 votes)
22 views3 pages

Demo #3 Slope Fields With Mathematica

The document discusses using Mathematica to generate a slope field and integral curve for the nonlinear first-order ODE y'[x] = y Cos[x]/(1 + 2 y^2). It shows how to write the ODE in standard form, generate the slope field, numerically solve for a specific solution satisfying an initial condition, and overlay the solution on the slope field.

Uploaded by

Iki Raul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Demo #3 Slope Fields With Mathematica

The document discusses using Mathematica to generate a slope field and integral curve for the nonlinear first-order ODE y'[x] = y Cos[x]/(1 + 2 y^2). It shows how to write the ODE in standard form, generate the slope field, numerically solve for a specific solution satisfying an initial condition, and overlay the solution on the slope field.

Uploaded by

Iki Raul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

demo3.

nb 1

Demo #3

Slope Fields with Mathematica


Consider the following nonlinear first-order ODE:

y'[x] = y Cos[x]/(1 + 2 y^2 )

Let's examine the possible types of solutions that


it can possess.

Our first step is to write the equation in standard


form, i.e. y'[x] = f[x,y], by defining the function:

f[x_ ,y_ ]:= y Cos[x]/( 1 + 2 y^2 )

Next, we make sure that the proper graphics


package has been loaded into Mathematica. (You should
examine all the packages available under Add-ons in
the Help menu):

<<Graphics`PlotField`

The slope field is drawn by the command:


demo3.nb 2

plt1= PlotVectorField[ {1,f[x,y]}, {x,-3,3},{y,-1,2}]

… Graphics …

Notice that I have named the plot "plt1" for later


reference. The possible solutions to the ODE must "thread" through this slope field
so that the solution is everywhere tangent to the field.

Next, we will generate an integral curve that represents


the specific solution of an initial value problem. Suppose
we are interested in the "particular solution" that
satisfies the initial condition y[0]=1. It turns out
that the equation is "separable", so that an (implicit) analytical solution is
available. To save time, however, lets generate it numerically:

Clear[y]

NDSolve[ {y'[x] == f[x, y[x]], y[0] ==1},y,{x,-3,3}]

88y ® InterpolatingFunction@88-3., 3.<<, <>D<<


demo3.nb 3

plt2=Plot[Evaluate[y[x] /. %], {x,-3,3}]

1.3

1.2

1.1

-3 -2 -1 1 2 3
0.9

0.8

0.7

… Graphics …

Next, we superimpose this ``integral curve'' on top of the


slope field, demonstrating explicitly how the
solution is everywhere tangent to the slope field:

Show[plt1,plt2]

… Graphics …

In summary, we see that the slope field is quite


useful for visualizing families of solutions to
first order ODE's and understanding qualitative
solution behavior.

You might also like