MapleDESolnEx10.mws

First Order Equations

Solutions ToWeb Site Examples

Here is some Maple code to solve  web site Exam I example 10 and graph the solution.

Example 10

First solve for x between 0 and 3.

>    ode1:=diff(y(x),x)=-2*y(x)+1;

ode1 := diff(y(x),x) = -2*y(x)+1

>    dsolve(ode1,{y(x)});

y(x) = 1/2+exp(-2*x)*_C1

>    dsolve({ode1,y(0)=0},{y(x)});

y(x) = 1/2-1/2*exp(-2*x)

>    f:=rhs(%);

f := 1/2-1/2*exp(-2*x)

Now solve for x greater than 3 with the necessary value for y(3) to give continuity at x = 3.

>    ode2:=diff(y(x),x)=-2*y(x);

ode2 := diff(y(x),x) = -2*y(x)

>    dsolve({ode2,y(3)=1/2-exp(-6)/2},{y(x)});

y(x) = exp(-2*x)*(1/2-1/2*exp(-6))/exp(-6)

>    g:=rhs(%);

g := exp(-2*x)*(1/2-1/2*exp(-6))/exp(-6)

Graph the solution.

>    h:=x->piecewise(x<=3,f,g);

h := proc (x) options operator, arrow; piecewise(x <= 3,f,g) end proc

>    with(plots):

Warning, the name changecoords has been redefined

>    plot(h(x),x=0..6,y=0..0.6);

[Maple Plot]

Here is another way of defining the solution function.

>    q(x):=piecewise(x<=3,f,g);

q(x) := PIECEWISE([1/2-1/2*exp(-2*x), x <= 3],[exp(-2*x)*(1/2-1/2*exp(-6))/exp(-6), otherwise])

>    plot(q(x),x=0..6,y=0..0.6);

[Maple Plot]

>