dfmore.mws

Plotting solution curves and direction fields

Example 1

> restart;with(DEtools):with(plots):

> dsolve(diff(y(t),t)=2*y(t) + t^2, y(t));

y(t) = -1/2*t^2-1/2*t-1/4+exp(2*t)*_C1

We pick a few initial condition and solve for the constant _C1. Use y(0)=0, y(0)=1, y(0)=-1.

> f := t -> -1/2*t^2-1/2*t-1/4+exp(2*t)*C;

f := proc (t) options operator, arrow; -1/2*t^2-1/2...

> solve(f(0)=0,C);

1/4

> solve(f(0)=1,C);

5/4

> solve(f(0)=-1,C);

-3/4

Now we plot these three curves.

> C:=1/4:

> plot1:=plot(f(t),t=-3..3,y=-10..10):

> C:=5/4:

> plot2:=plot(f(t),t=-3..3,y=-10..10):

> C:=-3/4:

> plot3:=plot(f(t),t=-3..3,y=-10..10):

> display(plot1,plot2,plot3);

[Maple Plot]

Let's set C=0. (Can you find the initial condition that does this?)

> C:=0:plot4:=plot(f(t),t=-3..3,y=-10..10,color=blue):

> display(plot1,plot2,plot3,plot4);

[Maple Plot]

Finally we look at the direction field.

> field:=dfieldplot(diff(y(t),t)=2*y(t)+t^2,y(t), t=-3..3,y=-10..10,arrows=line,color=black):

> display(field,plot1,plot2,plot3,plot4);

[Maple Plot]

Example 2:

> restart;with(DEtools):with(plots):

> dsolve(diff(y(t),t) - (1/t)*y(t) = t*tan(t), y(t));

y(t) = -t*ln(cos(t))+t*_C1

Maple does not like absolute values. The reasons for this are complex. So, instead of worrying about this I will just rewrite the solution with the absolute values.

> f := t -> -t*ln(abs(cos(t))) + C*t;

f := proc (t) options operator, arrow; -t*ln(abs(co...

This time we will do the direction field first.

> dfieldplot(diff(y(t),t) - (1/t)*y(t) = t*tan(t), y(t), t=-2*Pi..2*Pi, y=-5..5,arrows=line,color=black,dirgrid=[30,30]);

[Maple Plot]

Print this out and try to draw in some solution curves before proceding.

We find C for some initial conditions.

> solve(f(1)=1,C);

ln(cos(1))+1

> evalf(solve(f(1)=1,C));

.3843735297

> C1:=ln(cos(1))+1;

C1 := ln(cos(1))+1

> C2:=solve(f(1)=-2,C);

C2 := ln(cos(1))-2

> C3:=solve(f(-3)=0,C);

C3 := ln(-cos(3))

> C4:=solve(f(-5)=0,C);

C4 := ln(cos(5))

> C:=C1:

> plot(f(t),t=-2*Pi..2*Pi, y=-5..5);

[Maple Plot]

But this does not make sense. Our function is only guaranteed to exist, be unique and continuous in the interval (0,Pi/2). It looks like the solution would work on (-Pi/2, Pi/2). We will come back to this point later. The other branches of the plot are solution curves for different initial values. I'll go ahead and plot over the whole range, so we are realy using more initial condidtions than those explicitly stated.

> plot1:=plot(f(t),t=-2*Pi..2*Pi, y=-5..5):

> C:=C2:plot2:=plot(f(t),t=-2*Pi..2*Pi, y=-5..5):

> C:=C3:plot3:=plot(f(t),t=-2*Pi..2*Pi, y=-5..5):

> C:=C4:plot4:=plot(f(t),t=-2*Pi..2*Pi, y=-5..5):

> field:=dfieldplot(diff(y(t),t) - (1/t)*y(t) = t*tan(t), y(t), t=-2*Pi..2*Pi, y=-5..5,arrows=line,color=black,dirgrid=[30,30]):

> display(field,plot1,plot2,plot3,plot4);

[Maple Plot]

Notice that solutions through the origin are not unique!