Section 2.4: Mathematica Addition to Lecture

Sept 2015

Linear

Here is the direction fields for the linear case:

deq=y'[t]==((4 (t^2)-2 y[t])/t)
field=VectorPlot[{1,Last[deq]},{t,-2,2},{y[t],-1,3},VectorScale->{Tiny,Small,None},VectorPoints->20];
Show[field,Frame->True,FrameLabel->{"t","y(t)"},BaseStyle->Large]

Notice that at t=0, the derivative is infinite--we don’t want to exclude those values, and you can see the direction field does show an infinite derivative at t=0.

Here is how Mathematica solves the differential equation, and the two initial value problems discussed in class:

Clear[y]
DSolve[deq,y[t],t]
DSolve[{deq,y[1]==2},y[t],t]
DSolve[{deq,y[-1]==2},y[t],t]

Plots:

sol1=Plot[((1+(t^4))/(t^2)),{t,-2,0},PlotStyle->{Blue,Thickness[0.01]}];
sol2=Plot[((1+(t^4))/(t^2)),{t,0,2},PlotStyle->{Red,Dashed,Thick}];

Show[sol1,sol2,field,PlotRange->{{-2,2},{-1,3}},AspectRatio->1,Frame->True,FrameLabel->{"t","y(t)"},ImageSize->{400,Automatic},AxesOrigin->{0,0},BaseStyle->Large]

Notice the two solutions do not cross the line t=0, and we knew there would be a problem at t=0 before we solved the differential equation.

Nonlinear

First IVP with initial condition y(0)=1

Check our solution by doing implicit differentiation and recovering the original ODE:

D[3y[t]^2/2-y[t]^3/3==t+t^3/3+7/6,t]
Solve[%,y'[t]]

Check initial condition is satisfied by direct substitution:

3y[t]^2/2-y[t]^3/3==t+t^3/3+7/6/.y[t]->1/.t->0

Solve for explicit solutions contained in the impicit solution.

sols=Solve[3y^2/2-y^3/3==t+t^3/3+7/6,y]//Simplify

We've got three solutions--are they all real valued? Difficult to check, but we can plot them easily:

solplot=Plot[{sols[[1,1,2]],sols[[2,1,2]],sols[[3,1,2]]},{t,-2,2},PlotStyle->{Thickness[0.01]},FrameLabel->{"t","y"},Frame->True,BaseStyle->Large]

All three solutions are real valued in some region.

We see that only one solution passes through the point (0,1), which was our initial condition!

Here is the nonlinear direction field:

deq=y'[t]==((1+(t^2))/(3 y[t]-((y[t])^2)))
field=VectorPlot[{1,((1+(t^2))/(3 y-(y^2)))},{t,-2,2},{y,-2,5},FrameLabel->{"t","y(t)"},VectorScale->{Tiny,Small,None},VectorPoints->20];
Show[field,solplot,BaseStyle->Large]

Notice that the solution to our IVP (in green) is only valid for a finite value of t--which is something that we did not know until we had solved the initial value problem. This is typical of nonlinear problems.

From the above sketch, we can figure out the t values using the following to solve an equation:

NSolve[(3/2)(y^2)-(1/3)(y^3)==t+(1/3)(t^3)+(7/6)/.y->0,t]
NSolve[(3/2)(y^2)-(1/3)(y^3)==t+(1/3)(t^3)+(7/6)/.y->3,t]

Here is a sketch with the rectangle for which the solution to the IVP is unique and exists:

dot=Graphics[Disk[{0,1},{0.1,0.1/0.6}]];
rect=Graphics[{Opacity[0.25],Orange,Rectangle[{-0.912991,0},{1.69889,3}]}];

Show[field,dot,rect,solplot,Axes->True,PlotRange->{{-2,2},{-2,5}},AspectRatio->1,BaseStyle->Large]

Plotting a Portion of an Implicit Function

ContourPlot[3(y^2)/2-(y^3)/3==t+(t^3)/3+7/6,{t,-2,2},{y,-2,5},BaseStyle->Large,FrameLabel->{"t","y"}]

Adding a RegionFunction option to the plot allows you to show only the portion of the curve that is the solution to the IVP.

ContourPlot[3(y^2)/2-(y^3)/3==t+(t^3)/3+7/6,{t,-2,2},{y,-2,5},BaseStyle->Large,FrameLabel->{"t","y"},RegionFunction->Function[{x,y,z},-0.912991<x<1.69889&&0<y<3]]

Second IVP with initial condition y(0)=3

sols=Solve[(3/2)(y^2)-(1/3)(y^3)==t+(1/3)(t^3)+(9/2),y]//Simplify

Here are the plots of the three explicit solutions we found:

solplot=Plot[{sols[[1,1,2]],sols[[2,1,2]],sols[[3,1,2]]},{t,-3,3},PlotStyle->{Thick},AxesLabel->{"t","y"},BaseStyle->Large];

dot=Graphics[Disk[{0,3},{0.1,0.1/0.6}]];

Show[field,dot,solplot,Frame->True,BaseStyle->Large]

We see that two solutions pass through the point (0,3), which was our initial condition! The solution exists, but is not unique.