Skip to main content

Overview

Giac provides comprehensive differential equation solving capabilities, including symbolic methods (separation of variables, Laplace transforms, series solutions) and numerical methods (ODE solvers).

Symbolic ODE Solvers

desolve

Main symbolic differential equation solver.
gen desolve(const gen & f, const gen & x, const gen & y, int & ordre, 
            vecteur & parameters, GIAC_CONTEXT);
gen desolve_f(const gen & f_orig, const gen & x_orig, const gen & y_orig, 
              int & ordre, vecteur & parameters, gen & f, int step_info, 
              bool & num, GIAC_CONTEXT);
gen _desolve(const gen & args, GIAC_CONTEXT);
f
gen
required
Differential equation (can be an equation or expression)
x
gen
required
Independent variable
y
gen
required
Dependent variable (function to solve for)
ordre
int&
required
Output: order of the differential equation
parameters
vecteur&
required
Output: integration constants (c_0, c_1, …)
return
gen
General solution to the differential equation
// Solve dy/dx = y
// Solution: y = c_0 * exp(x)
identificateur x("x"), y("y");
gen ode = symb_equal(symb_derive(y, x), y);
gen args = makesequence(ode, x, y);
gen result = _desolve(args, context0);

separate_variables

Separation of variables for first-order ODEs.
bool separate_variables(const gen & f, const gen & x, const gen & y, 
                        gen & xfact, gen & yfact, GIAC_CONTEXT);
bool separate_variables(const gen & f, const gen & x, const gen & y, 
                        gen & xfact, gen & yfact, int step_info, GIAC_CONTEXT);
f
gen
required
Expression (usually from dy/dx = f(x,y) form)
x
gen
required
Independent variable
y
gen
required
Dependent variable
xfact
gen&
required
Output: factor depending only on x
yfact
gen&
required
Output: factor depending only on y
step_info
int
Level of step-by-step information to display
return
bool
True if variables can be separated
This function determines if an ODE can be written as M(x)dx + N(y)dy = 0.

Transform Methods

laplace

Laplace transform for solving ODEs.
gen laplace(const gen & f, const gen & x, const gen & s, GIAC_CONTEXT);
gen _laplace(const gen & args, GIAC_CONTEXT);
f
gen
required
Function to transform
x
gen
required
Time variable
s
gen
required
Frequency variable (transform domain)
return
gen
Laplace transform F(s) = ∫₀^∞ f(x)e^(-sx) dx
// L{sin(t)} = 1/(s^2 + 1)
identificateur t("t"), s("s");
gen result = laplace(sin(t), t, s, context0);

ilaplace

Inverse Laplace transform.
gen ilaplace(const gen & f, const gen & x, const gen & s, GIAC_CONTEXT);
gen _ilaplace(const gen & args, GIAC_CONTEXT);
f
gen
required
Function in frequency domain
s
gen
required
Frequency variable
x
gen
required
Time variable (output domain)
return
gen
Original function in time domain

ztrans

Z-transform for difference equations.
gen ztrans(const gen & f, const gen & x, const gen & s, GIAC_CONTEXT);
gen _ztrans(const gen & args, GIAC_CONTEXT);
f
gen
required
Discrete sequence
x
gen
required
Discrete variable (usually n)
s
gen
required
Transform variable (usually z)
The Z-transform is used for solving difference equations (discrete analogue of ODEs).

invztrans

Inverse Z-transform.
gen invztrans(const gen & f, const gen & x, const gen & s, GIAC_CONTEXT);
gen _invztrans(const gen & args, GIAC_CONTEXT);
// Solve a[n+1] = 2*a[n], a[0] = 1
// 1. Z-transform: z*A(z) - z*a[0] = 2*A(z)
// 2. Solve: A(z) = z/(z-2)
// 3. Inverse: a[n] = 2^n

Numerical ODE Solvers

odesolve

Numerical ODE solver for initial value problems.
gen odesolve(const gen & t0orig, const gen & t1orig, const gen & f, 
             const gen & y0orig, double tstep, bool return_curve, 
             double * ymin, double * ymax, int maxstep, GIAC_CONTEXT);
gen _odesolve(const gen & args, GIAC_CONTEXT);
t0orig
gen
required
Initial time t₀
t1orig
gen
required
Final time t₁
f
gen
required
Right-hand side function f(t,y) for dy/dt = f(t,y)
y0orig
gen
required
Initial condition y(t₀)
tstep
double
required
Time step for integration
return_curve
bool
required
If true, return array of [t, y(t)] pairs; if false, return only y(t₁)
ymin
double*
Minimum y value (for stopping early)
ymax
double*
Maximum y value (for stopping early)
maxstep
int
required
Maximum number of steps
return
gen
Solution value y(t₁) or array of solution curve
// Solve dy/dt = -y, y(0) = 1, from t=0 to t=1
identificateur t("t"), y("y");
gen f = makevecteur(-y, t, y); // [f(t,y), t, y]
gen result = odesolve(0, 1, f, 1, 0.01, false, NULL, NULL, 1000, context0);
// Returns: y(1) ≈ 0.368 (exact: 1/e)

Special ODE Methods

kovacicsols

Kovacic’s algorithm for second-order linear ODEs.
#ifndef USE_GMP_REPLACEMENTS
gen kovacicsols(const gen & r_orig, const gen & x, const gen & dy_coeff, 
                GIAC_CONTEXT);
gen _kovacicsols(const gen & g, GIAC_CONTEXT);
#endif
r_orig
gen
required
Coefficient function for y” = r(x)*y
x
gen
required
Independent variable
dy_coeff
gen
required
Coefficient of y’ (if not in canonical form)
Kovacic’s algorithm finds Liouvillian solutions (solutions involving algebraic functions, exponentials, and integrals) for second-order linear ODEs.

Utility Functions

diffeq_constante

Generate integration constant for DE solutions.
gen diffeq_constante(int i, GIAC_CONTEXT);
i
int
required
Index of constant (0 for c_0, 1 for c_1, etc.)
return
gen
Integration constant symbol

integrate_without_lnabs

Integration without absolute value in logarithms (for ODE solving).
gen integrate_without_lnabs(const gen & e, const gen & x, GIAC_CONTEXT);
e
gen
required
Expression to integrate
x
gen
required
Integration variable
Useful in ODE solving where ln|u| should be written as ln(u).

Matrix ODEs

Kronecker

Kronecker method for linear systems.
gen _Kronecker(const gen & args, GIAC_CONTEXT);
args
gen
required
Arguments for Kronecker method
Used for solving systems of linear ODEs with constant coefficients.

Notes

  • desolve attempts multiple methods: separation of variables, variation of parameters, series solutions
  • For linear ODEs with constant coefficients, characteristic equation method is used
  • Laplace transforms are particularly effective for initial value problems
  • Numerical solver uses adaptive step-size Runge-Kutta methods
  • Systems of ODEs can be solved by passing vectors for initial conditions
  • Boundary value problems require different approaches (shooting method, finite differences)
  • Stiff ODEs may require specialized solvers

Build docs developers (and LLMs) love