Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Separable Differential Equations

25 views

Separable Differential Equations

This is a Sage worksheet. It consists of "cells". Each "cell" contains several commands.

To "execute" a cell, i.e. to execute the commands of a cell, press Shift+Enter.

You can use this worksheet to:

1) Solve differential equations

2) Use an initial condition

3) Draw the direction field

4) Draw the integral curves

Example:

Consider the differential equation:

dy/dx= 2x/(y+x^2*y) which can written as dy/dy- 2x/(y+x^2*y)=0

The next cell uses the command desolve to solve a differential equation.

The quantity diff(y,x)- 2*x/(y+x^2*y) is the left-side of the equation dy/dx- 2*x/(y+x^2*y)=0.

Notes:

(1) diff(y,x) stands for the derivative of y with respect to x.

(2) Sage will understand 2*x, but will give an error for 2x

(3) Sage can not solve ALL differential equations.

The output of the cell is the implicit solution of the differential equation.

Observe that the implicit solution contains the constant c.

x = var('x') y = function('y', x) desolve(diff(y,x)- x+1+y^2, y)
Error in lines 3-3 Traceback (most recent call last): File "/projects/a62de059-5442-4285-bca1-ad714c016830/.sagemathcloud/sage_server.py", line 873, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/calculus/desolvers.py", line 463, in desolve raise NotImplementedError("Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.") NotImplementedError: Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.
The next cell solves the same differential equation as before, dy/dx- 2*x/(y+x^2*y)=0, but this time the initial condition y(0)=-2 is used.

The initial condition is given by the command ics=[0,-2].

The output of the cell is the implicit solution of the differential equation, but this time, there is no c involved.

x = var('x') y = function('y', x) desolve(diff(y,x)- 2*x/(y+x^2*y), y,ics=[0,-2]);
1/4*y(x)^2 == 1/2*log(x^2 + 1) + 1
The next cell plots the integral curve 1/4*y(x)^2 == 1/2*log(x^2 + 1) + 1. This is the implicit solution we found from the previous cell.

If you copy and paste the implicit solution from the previous cell to this cell, be careful to replace y(x) with y.

I.e. 1/4*y(x)^2 == 1/2*log(x^2 + 1) + 1 becomes 1/4*y^2 == 1/2*log(x^2 + 1) + 1.

If you do not replace y(x) by y, either you will get an error message, or the plot will be inaccurate.

The viewing window is from x=-5 to x=5 and from y=-5 to y=5. Adjust this accordingly.

var('x y') implicit_plot(1/4*y^2 == 1/2*log(x^2 + 1) + 1,(x,-5,5),(y,-5,5))
(x, y)
The next cell plots 5 integral curves together.

From the first cell we know that the implicit solution of the diff.eq. dy/dy- 2x/(y+x^2*y)=0 equals 1/4*y^2 == c + 1/2*log(x^2 + 1).

Different values of c will give different integral curves.

The command "implicit_plot(1/4*y^2 == 1 + 1/2*log(x^2 + 1),(x,-5,5),(y,-5,5))+implicit_plot(1/4*y^2 == 2 + 1/2*log(x^2 + 1),(x,-5,5),(y,-5,5))" will generate two implicit plots, the one on top of the other.

Instead of adding many implicit plots together, we use the sum() command and we specify the values for the c.

var('x y') sum([implicit_plot(1/4*y^2 == c + 1/2*log(x^2 + 1),(x,-5,5),(y,-5,5)) for c in [0,1,2,3,4]])
(x, y)
The next cell plots the slope field of the differential equation dy/dy= 2x/(y+x^2*y).

We enter only the right-hand side 2x/(y+x^2*y), and we adjust the viewing window for our purposes

var('x','y') plot_slope_field(x-1-y^2, (x,-1,10), (y,-5,5))
(x, y)
The next cell plots the slope field and one integral curve together (using +).

The commands for plot_slope_field and implicit_plot are the same we used before.

var('x','y') plot_slope_field(2*x/(y+x^2*y), (x,-5,5), (y,-5,5))+implicit_plot(1/4*y^2 == 1/2*log(x^2 + 1) + 1,(x,-5,5),(y,-5,5))
(x, y)
The next cell plots the slope field and five integral curve together (using +).

The commands for plot_slope_field and implicit_plot are the same we used before.

var('x','y') plot_slope_field(2*x/(y+x^2*y), (x,-5,5), (y,-5,5))+sum([implicit_plot(1/4*y^2 == c + 1/2*log(x^2 + 1),(x,-5,5),(y,-5,5)) for c in [0,1,2,3,4]])
(x, y)
To edit a new cell click on the line between two consecutive cells or on the line at the end of the worksheet.