@menu
* Introduction to Differential Equations::  
* Functions and Variables for Differential Equations::  
@end menu

@node Introduction to Differential Equations, Functions and Variables for Differential Equations, Differential Equations, Differential Equations
@section Introduction to Differential Equations

This section describes the functions available in Maxima to obtain
analytic solutions for some specific types of first and second-order
equations. To obtain a numerical solution for a system of differential
equations, see the additional package @code{dynamics}. For graphical
representations in phase space, see the additional package
@code{plotdf}.

@node Functions and Variables for Differential Equations,  , Introduction to Differential Equations, Differential Equations
@section Functions and Variables for Differential Equations

@anchor{bc2}
@deffn {Function} bc2 (@var{solution}, @var{xval1}, @var{yval1}, @var{xval2}, @var{yval2})
Solves a boundary value problem for a second order differential equation.
Here: @var{solution} is a general solution to the equation, as found by
@code{ode2}; @var{xval1} specifies the value of the independent variable
in a first point, in the form @code{@var{x} = @var{x1}}, and @var{yval1}
gives the value of the dependent variable in that point, in the form
@code{@var{y} = @var{y1}}. The expressions @var{xval2} and @var{yval2}
give the values for these variables at a second point, using the same
form.

See @mref{ode2} for an example of its usage.

@opencatbox{Categories:}
@category{Differential equations}
@closecatbox
@end deffn

@anchor{desolve}
@deffn {Function} desolve @
@fname{desolve} (@var{eqn}, @var{y}) @
@fname{desolve} ([@var{eqn_1}, ..., @var{eqn_n}], [@var{y_1}, ..., @var{y_n}])

The function @code{desolve} solves systems of linear ordinary
differential equations using Laplace transform. Here the @var{eqn}'s are
differential equations in the dependent variables @var{y_1}, ...,
@var{y_n}. The functional dependence of @var{y_1}, ..., @var{y_n} on an
independent variable, for instance @var{x}, must be explicitly indicated
in the variables and its derivatives. For example, the @emph{correct}
way to define the differential equations would be:

@example
eqn_1: 'diff(f(x),x,2) = sin(x) + 'diff(g(x),x);
eqn_2: 'diff(f(x),x) + x^2 - f(x) = 2*'diff(g(x),x,2);
@end example

The call to the function @code{desolve} would then be:
@example
desolve([eqn_1, eqn_2], [f(x),g(x)]);
@end example

If initial conditions at @code{x=0} are known, they can be supplied before
calling @code{desolve} by using @code{atvalue}.

@c ===beg===
@c 'diff(f(x),x)='diff(g(x),x)+sin(x);
@c 'diff(g(x),x,2)='diff(f(x),x)-cos(x);
@c atvalue('diff(g(x),x),x=0,a);
@c atvalue(f(x),x=0,1);
@c desolve([%o1,%o2],[f(x),g(x)]);
@c [%o1,%o2],%o5,diff;
@c ===end===
@example
(%i1) 'diff(f(x),x)='diff(g(x),x)+sin(x);
                 d           d
(%o1)            -- (f(x)) = -- (g(x)) + sin(x)
                 dx          dx
(%i2) 'diff(g(x),x,2)='diff(f(x),x)-cos(x);
@group
                  2
                 d            d
(%o2)            --- (g(x)) = -- (f(x)) - cos(x)
                   2          dx
                 dx
@end group
(%i3) atvalue('diff(g(x),x),x=0,a);
(%o3)                           a
(%i4) atvalue(f(x),x=0,1);
(%o4)                           1
(%i5) desolve([%o1,%o2],[f(x),g(x)]);
                  x
(%o5) [f(x) = a %e  - a + 1, g(x) = 

                                                x
                                   cos(x) + a %e  - a + g(0) - 1]
(%i6) [%o1,%o2],%o5,diff;
             x       x      x                x
(%o6)   [a %e  = a %e , a %e  - cos(x) = a %e  - cos(x)]

@end example

If @code{desolve} cannot obtain a solution, it returns @code{false}.

See also @mrefcomma{ode2} @mref{drawdf} and @mrefdot{rk}

@opencatbox{Categories:}
@category{Differential equations}
@category{Laplace transform}
@closecatbox
@end deffn
@anchor{ic1}
@deffn {Function} ic1 (@var{solution}, @var{xval}, @var{yval})
Solves initial value problems for first order differential equations.
Here @var{solution} is a general solution to the equation, as found by
@mref{ode2}, @var{xval} gives an initial value for the independent
variable in the form @code{@var{x} = @var{x0}}, and @var{yval} gives the
initial value for the dependent variable in the form @code{@var{y} =
@var{y0}}.

See @mref{ode2} for an example of its usage.

@opencatbox{Categories:}
@category{Differential equations}
@closecatbox
@end deffn
@anchor{ic2}
@deffn {Function} ic2 (@var{solution}, @var{xval}, @var{yval}, @var{dval})
Solves initial value problems for second-order differential equations.
Here @var{solution} is a general solution to the equation, as found by
@code{ode2}, @var{xval} gives the initial value for the independent
variable in the form @code{@var{x} = @var{x0}}, @var{yval} gives the
initial value of the dependent variable in the form @code{@var{y} =
@var{y0}}, and @var{dval} gives the initial value for the first
derivative of the dependent variable with respect to independent
variable, in the form @code{diff(@var{y},@var{x}) = @var{dy0}}
(@code{diff} does not have to be quoted).

See @mref{ode2} for an example of its usage.

@opencatbox{Categories:}
@category{Differential equations}
@closecatbox
@end deffn

@anchor{ode2}
@deffn {Function} ode2 (@var{eqn}, @var{dvar}, @var{ivar})
The function @code{ode2} solves an ordinary differential equation (ODE)
of first or second order. It takes three arguments: an ODE given by
@var{eqn}, the dependent variable @var{dvar}, and the independent
variable @var{ivar}. When successful, it returns either an explicit or
implicit solution for the dependent variable. @code{%c} is used to
represent the integration constant in the case of first-order equations,
and @code{%k1} and @code{%k2} the constants for second-order
equations. The dependence of the dependent variable on the independent
variable does not have to be written explicitly, as in the case of
@code{desolve}, but the independent variable must always be given as the
third argument.

If @code{ode2} cannot obtain a solution for whatever reason, it returns
@code{false}, after perhaps printing out an error message. The methods
implemented for first order equations in the order in which they are
tested are: linear, separable, exact - perhaps requiring an integrating
factor, homogeneous, Bernoulli's equation, and a generalized homogeneous
method. The types of second-order equations which can be solved are:
constant coefficients, exact, linear homogeneous with non-constant
coefficients which can be transformed to constant coefficients, the
Euler or equi-dimensional equation, equations solvable by the method of
variation of parameters, and equations which are free of either the
independent or of the dependent variable so that they can be reduced to
two first order linear equations to be solved sequentially.

In the course of solving ODE's, several variables are set purely for
informational purposes: @code{method} denotes the method of solution
used (e.g., @code{linear}), @code{intfactor} denotes any integrating
factor used, @code{odeindex} denotes the index for Bernoulli's method or
for the generalized homogeneous method, and @code{yp} denotes the
particular solution for the variation of parameters technique.

In order to solve initial value problems (IVP) functions @mref{ic1} and
@mref{ic2} are available for first and second order equations, and to
solve second-order boundary value problems (BVP) the function @mref{bc2}
can be used.

See also @mrefcomma{desolve} @mref{drawdf} and @mrefdot{rk}

Example:

@c ===beg===
@c x^2*'diff(y,x) + 3*y*x = sin(x)/x;
@c ode2(%,y,x);
@c ic1(%o2,x=%pi,y=0);
@c 'diff(y,x,2) + y*'diff(y,x)^3 = 0;
@c ode2(%,y,x);
@c ratsimp(ic2(%o5,x=0,y=0,'diff(y,x)=2));
@c bc2(%o5,x=0,y=1,x=1,y=3);
@c ===end===
@example
(%i1) x^2*'diff(y,x) + 3*y*x = sin(x)/x;
                      2 dy           sin(x)
(%o1)                x  -- + 3 x y = ------
                        dx             x
(%i2) ode2(%,y,x);
                             %c - cos(x)
(%o2)                    y = -----------
                                  3
                                 x
(%i3) ic1(%o2,x=%pi,y=0);
                              cos(x) + 1
(%o3)                   y = - ----------
                                   3
                                  x
(%i4) 'diff(y,x,2) + y*'diff(y,x)^3 = 0;
                         2
                        d y      dy 3
(%o4)                   --- + y (--)  = 0
                          2      dx
                        dx
(%i5) ode2(%,y,x);
                      3
                     y  + 6 %k1 y
(%o5)                ------------ = x + %k2
                          6
(%i6) ratsimp(ic2(%o5,x=0,y=0,'diff(y,x)=2));
@group
                             3
                          2 y  - 3 y
(%o6)                   - ---------- = x
                              6
@end group
(%i7) bc2(%o5,x=0,y=1,x=1,y=3);
                         3
                        y  - 10 y       3
(%o7)                   --------- = x - -
                            6           2

@end example

@opencatbox{Categories:}
@category{Differential equations}
@closecatbox
@end deffn
