11.11.2014 Views

Introductory Differential Equations using Sage - William Stein

Introductory Differential Equations using Sage - William Stein

Introductory Differential Equations using Sage - William Stein

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1.4. FIRST ORDER ODES - SEPARABLE AND LINEAR CASES 25<br />

(e) If c = c(t) is not constant then ax ′ + bx = c is not separable.<br />

(f)<br />

dy<br />

(y−1)(y+1) = dt so 1 2<br />

(ln(y −1)−ln(y+1)) = t+C, where C is a constant of integration.<br />

This is the “general (implicit) solution” of the DE.<br />

Note: the constant functions y(t) = 1 and y(t) = −1 are also solutions to this DE.<br />

These solutions cannot be obtained (in an obvious way) from the general solution.<br />

The integral is easy to do <strong>using</strong> <strong>Sage</strong>:<br />

<strong>Sage</strong><br />

sage: y = var(’y’)<br />

sage: integral(1/((y-1)*(y+1)),y)<br />

log(y - 1)/2 - (log(y + 1)/2)<br />

Now, let’s try to get <strong>Sage</strong> to solve for y in terms of t in 1 2<br />

(ln(y −1)−ln(y+1)) = t+C:<br />

<strong>Sage</strong><br />

sage: C = var(’C’)<br />

sage: solve([log(y - 1)/2 - (log(y + 1)/2) == t+C],y)<br />

[log(y + 1) == -2*C + log(y - 1) - 2*t]<br />

This is not working. Let’s try inputting the problem in a different form:<br />

<strong>Sage</strong><br />

sage: C = var(’C’)<br />

sage: solve([log((y - 1)/(y + 1)) == 2*t+2*C],y)<br />

[y == (-eˆ(2*C + 2*t) - 1)/(eˆ(2*C + 2*t) - 1)]<br />

This is what we want. Now let’s assume the initial condition y(0) = 2 and solve for<br />

C and plot the function.<br />

<strong>Sage</strong><br />

sage: solny=lambda t:(-eˆ(2*C+2*t)-1)/(eˆ(2*C+2*t)-1)<br />

sage: solve([solny(0) == 2],C)<br />

[C == log(-1/sqrt(3)), C == -log(3)/2]<br />

sage: C = -log(3)/2<br />

sage: solny(t)<br />

(-eˆ(2*t)/3 - 1)/(eˆ(2*t)/3 - 1)<br />

sage: P = plot(solny(t), 0, 1/2)<br />

sage: show(P)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!