|
File: /usr/local/sage/local/lib/python2.6/site-packages/sage/calculus/desolvers.py
Type: <type ‘function’>
Definition: desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False)
Docstring:
Solves a 1st or 2nd order linear ODE via maxima. Including IVP and BVP.
Use desolve? <tab> if the output in truncated in notebook.
INPUT:
- de - an expression or equation representing the ODE
- dvar - the dependent variable (hereafter called y)
- ics - (optional) the initial or boundary conditions
- for a first-order equation, specify the initial x and y
- for a second-order equation, specify the initial x, y,
and dy/dx, i.e. write [x_0, y(x_0), y'(x_0)]
- for a second-order boundary solution, specify initial and
final x and y boundary conditions, i.e. write [x_0, y(x_0), x_1, y(x_1)].
- gives an error if the solution is not SymbolicEquation (as happens for
example for Clairaut equation)
- ivar - (optional) the independent variable (hereafter called
x), which must be specified if there is more than one
independent variable in the equation.
- show_method - (optional) if true, then Sage returns pair
[solution, method], where method is the string describing
method which has been used to get solution (Maxima uses the
following order for first order equations: linear, separable,
exact (including exact with integrating factor), homogeneous,
bernoulli, generalized homogeneous) - use carefully in class,
see below for the example of the equation which is separable but
this property is not recognized by Maxima and equation is solved
as exact.
- contrib_ode - (optional) if true, desolve allows to solve
clairaut, lagrange, riccati and some other equations. May take
a long time and thus turned off by default. Initial conditions
can be used only if the result is one SymbolicEquation (does not
contain singular solution, for example)
OUTPUT:
In most cases returns SymbolicEquation which defines the solution
implicitly. If the result is in the form y(x)=... (happens for
linear eqs.), returns the right-hand side only. The possible
constant solutions of separable ODE’s are omitted.
EXAMPLES:
sage: x = var('x')
sage: y = function('y', x)
sage: desolve(diff(y,x) + y - 1, y)
(c + e^x)*e^(-x)
sage: f = desolve(diff(y,x) + y - 1, y, ics=[10,2]); f
(e^10 + e^x)*e^(-x)
We can also solve second-order differential equations.:
sage: x = var('x')
sage: y = function('y', x)
sage: de = diff(y,x,2) - y == x
sage: desolve(de, y)
k1*e^x + k2*e^(-x) - x
sage: f = desolve(de, y, [10,2,1]); f
-x + 5*e^(-x + 10) + 7*e^(x - 10)
sage: de = diff(y,x,2) + y == 0
sage: desolve(de, y)
k1*sin(x) + k2*cos(x)
sage: desolve(de, y, [0,1,pi/2,4])
4*sin(x) + cos(x)
sage: desolve(y*diff(y,x)+sin(x)==0,y)
-1/2*y(x)^2 == c - cos(x)
Clairot equation: general and singular solutions:
sage: desolve(diff(y,x)^2+x*diff(y,x)-y==0,y,contrib_ode=True,show_method=True)
[[y(x) == c^2 + c*x, y(x) == -1/4*x^2], 'clairault']
For equations involving more variables we specify independent variable:
sage: a,b,c,n=var('a b c n')
sage: desolve(x^2*diff(y,x)==a+b*x^n+c*x^2*y^2,y,ivar=x,contrib_ode=True)
[[y(x) == 0, (b*x^(n - 2) + a/x^2)*c^2*u == 0]]
sage: desolve(x^2*diff(y,x)==a+b*x^n+c*x^2*y^2,y,ivar=x,contrib_ode=True,show_method=True)
[[[y(x) == 0, (b*x^(n - 2) + a/x^2)*c^2*u == 0]], 'riccati']
Higher orded, not involving independent variable:
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y).expand()
1/6*y(x)^3 + k1*y(x) == k2 + x
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,1,3]).expand()
1/6*y(x)^3 - 5/3*y(x) == x - 3/2
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,1,3],show_method=True)
[1/6*y(x)^3 - 5/3*y(x) == x - 3/2, 'freeofx']
Separable equations - Sage returns solution in implicit form:
sage: desolve(diff(y,x)*sin(y) == cos(x),y)
-cos(y(x)) == c + sin(x)
sage: desolve(diff(y,x)*sin(y) == cos(x),y,show_method=True)
[-cos(y(x)) == c + sin(x), 'separable']
sage: desolve(diff(y,x)*sin(y) == cos(x),y,[pi/2,1])
-cos(y(x)) == sin(x) - cos(1) - 1
Linear equation - Sage returns the expression on the right hand side only:
sage: desolve(diff(y,x)+(y) == cos(x),y)
1/2*((sin(x) + cos(x))*e^x + 2*c)*e^(-x)
sage: desolve(diff(y,x)+(y) == cos(x),y,show_method=True)
[1/2*((sin(x) + cos(x))*e^x + 2*c)*e^(-x), 'linear']
sage: desolve(diff(y,x)+(y) == cos(x),y,[0,1])
1/2*(e^x*sin(x) + e^x*cos(x) + 1)*e^(-x)
This ODE with separated variables is solved as
exact. Explanation - factor does not split e^{x-y} in Maxima
into e^{x}e^{y}:
sage: desolve(diff(y,x)==exp(x-y),y,show_method=True)
[-e^x + e^y(x) == c, 'exact']
You can solve Bessel equations. You can also use initial
conditions, but you cannot put (sometimes desired) initial
condition at x=0, since this point is singlar point of the
equation. Anyway, if the solution should be bounded at x=0, then
k2=0.:
sage: desolve(x^2*diff(y,x,x)+x*diff(y,x)+(x^2-4)*y==0,y)
k1*bessel_j(2, x) + k2*bessel_y(2, x)
Difficult ODE produces error:
sage: desolve(sqrt(y)*diff(y,x)+e^(y)+cos(x)-sin(x+y)==0,y) # not tested
Traceback (click to the left for traceback)
...
NotImplementedError, "Maxima was unable to solve this ODE. Consider to set option contrib_ode to True."
Difficult ODE produces error - moreover, takes a long time
sage: desolve(sqrt(y)*diff(y,x)+e^(y)+cos(x)-sin(x+y)==0,y,contrib_ode=True) # not tested
Some more types od ODE’s:
sage: desolve(x*diff(y,x)^2-(1+x*y)*diff(y,x)+y==0,y,contrib_ode=True,show_method=True)
[[y(x) == c + log(x), y(x) == c*e^x], 'factor']
sage: desolve(diff(y,x)==(x+y)^2,y,contrib_ode=True,show_method=True)
[[[x == c - arctan(sqrt(t)), y(x) == -x - sqrt(t)], [x == c + arctan(sqrt(t)), y(x) == -x + sqrt(t)]], 'lagrange']
These two examples produce error (as expected, Maxima 5.18 cannot
solve equations from initial conditions). Current Maxima 5.18
returns false answer in this case!:
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,2]).expand() # not tested
Traceback (click to the left for traceback)
...
NotImplementedError, "Maxima was unable to solve this ODE. Consider to set option contrib_ode to True."
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,2],show_method=True) # not tested
Traceback (click to the left for traceback)
...
NotImplementedError, "Maxima was unable to solve this ODE. Consider to set option contrib_ode to True."
Second order linear ODE:
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y)
(k2*x + k1)*e^(-x) + 1/2*sin(x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,show_method=True)
[(k2*x + k1)*e^(-x) + 1/2*sin(x), 'variationofparameters']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,1])
1/2*(7*x + 6)*e^(-x) + 1/2*sin(x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,1],show_method=True)
[1/2*(7*x + 6)*e^(-x) + 1/2*sin(x), 'variationofparameters']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,pi/2,2])
3*((e^(1/2*pi) - 2)*x/pi + 1)*e^(-x) + 1/2*sin(x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,pi/2,2],show_method=True)
[3*((e^(1/2*pi) - 2)*x/pi + 1)*e^(-x) + 1/2*sin(x), 'variationofparameters']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y)
(k2*x + k1)*e^(-x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,show_method=True)
[(k2*x + k1)*e^(-x), 'constcoeff']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,1])
(4*x + 3)*e^(-x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,1],show_method=True)
[(4*x + 3)*e^(-x), 'constcoeff']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,pi/2,2])
(2*(2*e^(1/2*pi) - 3)*x/pi + 3)*e^(-x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,pi/2,2],show_method=True)
[(2*(2*e^(1/2*pi) - 3)*x/pi + 3)*e^(-x), 'constcoeff']
TESTS:
Trac #9961 fixed (allow assumptions on the dependent variable in desolve):
sage: y=function('y',x); assume(x>0); assume(y>0)
sage: desolve(x*diff(y,x)-x*sqrt(y^2+x^2)-y == 0, y, contrib_ode=True)
[x - arcsinh(y(x)/x) == c]
Trac #6479 fixed:
sage: x = var('x')
sage: y = function('y', x)
sage: desolve( diff(y,x,x) == 0, y, [0,0,1])
x
sage: desolve( diff(y,x,x) == 0, y, [0,1,1])
x + 1
Trac #9835 fixed:
sage: x = var('x')
sage: y = function('y', x)
sage: desolve(diff(y,x,2)+y*(1-y^2)==0,y,[0,-1,1,1])
Traceback (click to the left of this block for traceback)
...
File: /usr/local/sage/local/lib/python2.6/site-packages/sage/calculus/desolvers.py
Type: <type ‘function’>
Definition: desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False)
Docstring:
Solves a 1st or 2nd order linear ODE via maxima. Including IVP and BVP.
Use desolve? <tab> if the output in truncated in notebook.
INPUT:
- de - an expression or equation representing the ODE
- dvar - the dependent variable (hereafter called y)
- ics - (optional) the initial or boundary conditions
- for a first-order equation, specify the initial x and y
- for a second-order equation, specify the initial x, y,
and dy/dx, i.e. write [x_0, y(x_0), y'(x_0)]
- for a second-order boundary solution, specify initial and
final x and y boundary conditions, i.e. write [x_0, y(x_0), x_1, y(x_1)].
- gives an error if the solution is not SymbolicEquation (as happens for
example for Clairaut equation)
- ivar - (optional) the independent variable (hereafter called
x), which must be specified if there is more than one
independent variable in the equation.
- show_method - (optional) if true, then Sage returns pair
[solution, method], where method is the string describing
method which has been used to get solution (Maxima uses the
following order for first order equations: linear, separable,
exact (including exact with integrating factor), homogeneous,
bernoulli, generalized homogeneous) - use carefully in class,
see below for the example of the equation which is separable but
this property is not recognized by Maxima and equation is solved
as exact.
- contrib_ode - (optional) if true, desolve allows to solve
clairaut, lagrange, riccati and some other equations. May take
a long time and thus turned off by default. Initial conditions
can be used only if the result is one SymbolicEquation (does not
contain singular solution, for example)
OUTPUT:
In most cases returns SymbolicEquation which defines the solution
implicitly. If the result is in the form y(x)=... (happens for
linear eqs.), returns the right-hand side only. The possible
constant solutions of separable ODE’s are omitted.
EXAMPLES:
sage: x = var('x')
sage: y = function('y', x)
sage: desolve(diff(y,x) + y - 1, y)
(c + e^x)*e^(-x)
sage: f = desolve(diff(y,x) + y - 1, y, ics=[10,2]); f
(e^10 + e^x)*e^(-x)
We can also solve second-order differential equations.:
sage: x = var('x')
sage: y = function('y', x)
sage: de = diff(y,x,2) - y == x
sage: desolve(de, y)
k1*e^x + k2*e^(-x) - x
sage: f = desolve(de, y, [10,2,1]); f
-x + 5*e^(-x + 10) + 7*e^(x - 10)
sage: de = diff(y,x,2) + y == 0
sage: desolve(de, y)
k1*sin(x) + k2*cos(x)
sage: desolve(de, y, [0,1,pi/2,4])
4*sin(x) + cos(x)
sage: desolve(y*diff(y,x)+sin(x)==0,y)
-1/2*y(x)^2 == c - cos(x)
Clairot equation: general and singular solutions:
sage: desolve(diff(y,x)^2+x*diff(y,x)-y==0,y,contrib_ode=True,show_method=True)
[[y(x) == c^2 + c*x, y(x) == -1/4*x^2], 'clairault']
For equations involving more variables we specify independent variable:
sage: a,b,c,n=var('a b c n')
sage: desolve(x^2*diff(y,x)==a+b*x^n+c*x^2*y^2,y,ivar=x,contrib_ode=True)
[[y(x) == 0, (b*x^(n - 2) + a/x^2)*c^2*u == 0]]
sage: desolve(x^2*diff(y,x)==a+b*x^n+c*x^2*y^2,y,ivar=x,contrib_ode=True,show_method=True)
[[[y(x) == 0, (b*x^(n - 2) + a/x^2)*c^2*u == 0]], 'riccati']
Higher orded, not involving independent variable:
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y).expand()
1/6*y(x)^3 + k1*y(x) == k2 + x
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,1,3]).expand()
1/6*y(x)^3 - 5/3*y(x) == x - 3/2
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,1,3],show_method=True)
[1/6*y(x)^3 - 5/3*y(x) == x - 3/2, 'freeofx']
Separable equations - Sage returns solution in implicit form:
sage: desolve(diff(y,x)*sin(y) == cos(x),y)
-cos(y(x)) == c + sin(x)
sage: desolve(diff(y,x)*sin(y) == cos(x),y,show_method=True)
[-cos(y(x)) == c + sin(x), 'separable']
sage: desolve(diff(y,x)*sin(y) == cos(x),y,[pi/2,1])
-cos(y(x)) == sin(x) - cos(1) - 1
Linear equation - Sage returns the expression on the right hand side only:
sage: desolve(diff(y,x)+(y) == cos(x),y)
1/2*((sin(x) + cos(x))*e^x + 2*c)*e^(-x)
sage: desolve(diff(y,x)+(y) == cos(x),y,show_method=True)
[1/2*((sin(x) + cos(x))*e^x + 2*c)*e^(-x), 'linear']
sage: desolve(diff(y,x)+(y) == cos(x),y,[0,1])
1/2*(e^x*sin(x) + e^x*cos(x) + 1)*e^(-x)
This ODE with separated variables is solved as
exact. Explanation - factor does not split e^{x-y} in Maxima
into e^{x}e^{y}:
sage: desolve(diff(y,x)==exp(x-y),y,show_method=True)
[-e^x + e^y(x) == c, 'exact']
You can solve Bessel equations. You can also use initial
conditions, but you cannot put (sometimes desired) initial
condition at x=0, since this point is singlar point of the
equation. Anyway, if the solution should be bounded at x=0, then
k2=0.:
sage: desolve(x^2*diff(y,x,x)+x*diff(y,x)+(x^2-4)*y==0,y)
k1*bessel_j(2, x) + k2*bessel_y(2, x)
Difficult ODE produces error:
sage: desolve(sqrt(y)*diff(y,x)+e^(y)+cos(x)-sin(x+y)==0,y) # not tested
Traceback (click to the left for traceback)
...
NotImplementedError, "Maxima was unable to solve this ODE. Consider to set option contrib_ode to True."
Difficult ODE produces error - moreover, takes a long time
sage: desolve(sqrt(y)*diff(y,x)+e^(y)+cos(x)-sin(x+y)==0,y,contrib_ode=True) # not tested
Some more types od ODE’s:
sage: desolve(x*diff(y,x)^2-(1+x*y)*diff(y,x)+y==0,y,contrib_ode=True,show_method=True)
[[y(x) == c + log(x), y(x) == c*e^x], 'factor']
sage: desolve(diff(y,x)==(x+y)^2,y,contrib_ode=True,show_method=True)
[[[x == c - arctan(sqrt(t)), y(x) == -x - sqrt(t)], [x == c + arctan(sqrt(t)), y(x) == -x + sqrt(t)]], 'lagrange']
These two examples produce error (as expected, Maxima 5.18 cannot
solve equations from initial conditions). Current Maxima 5.18
returns false answer in this case!:
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,2]).expand() # not tested
Traceback (click to the left for traceback)
...
NotImplementedError, "Maxima was unable to solve this ODE. Consider to set option contrib_ode to True."
sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,2],show_method=True) # not tested
Traceback (click to the left for traceback)
...
NotImplementedError, "Maxima was unable to solve this ODE. Consider to set option contrib_ode to True."
Second order linear ODE:
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y)
(k2*x + k1)*e^(-x) + 1/2*sin(x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,show_method=True)
[(k2*x + k1)*e^(-x) + 1/2*sin(x), 'variationofparameters']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,1])
1/2*(7*x + 6)*e^(-x) + 1/2*sin(x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,1],show_method=True)
[1/2*(7*x + 6)*e^(-x) + 1/2*sin(x), 'variationofparameters']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,pi/2,2])
3*((e^(1/2*pi) - 2)*x/pi + 1)*e^(-x) + 1/2*sin(x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,pi/2,2],show_method=True)
[3*((e^(1/2*pi) - 2)*x/pi + 1)*e^(-x) + 1/2*sin(x), 'variationofparameters']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y)
(k2*x + k1)*e^(-x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,show_method=True)
[(k2*x + k1)*e^(-x), 'constcoeff']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,1])
(4*x + 3)*e^(-x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,1],show_method=True)
[(4*x + 3)*e^(-x), 'constcoeff']
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,pi/2,2])
(2*(2*e^(1/2*pi) - 3)*x/pi + 3)*e^(-x)
sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,pi/2,2],show_method=True)
[(2*(2*e^(1/2*pi) - 3)*x/pi + 3)*e^(-x), 'constcoeff']
TESTS:
Trac #9961 fixed (allow assumptions on the dependent variable in desolve):
sage: y=function('y',x); assume(x>0); assume(y>0)
sage: desolve(x*diff(y,x)-x*sqrt(y^2+x^2)-y == 0, y, contrib_ode=True)
[x - arcsinh(y(x)/x) == c]
Trac #6479 fixed:
sage: x = var('x')
sage: y = function('y', x)
sage: desolve( diff(y,x,x) == 0, y, [0,0,1])
x
sage: desolve( diff(y,x,x) == 0, y, [0,1,1])
x + 1
Trac #9835 fixed:
sage: x = var('x')
sage: y = function('y', x)
sage: desolve(diff(y,x,2)+y*(1-y^2)==0,y,[0,-1,1,1])
Traceback (most recent call last):
...
NotImplementedError: Unable to use initial condition for this equation (freeofx).
Trac #8931 fixed:
sage: x=var('x'); f=function('f',x); k=var('k'); assume(k>0)
sage: desolve(diff(f,x,2)/f==k,f,ivar=x)
k1*e^(sqrt(k)*x) + k2*e^(-sqrt(k)*x)
AUTHORS:
- David Joyner (1-2006)
- Robert Bradshaw (10-2008)
- Robert Marik (10-2009)
|