Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
/*
 * This file:
 *   http://anggtwu.net/MAXIMA/2026-gosse.mac.html
 *   http://anggtwu.net/MAXIMA/2026-gosse.mac
 *          (find-angg "MAXIMA/2026-gosse.mac")
 *     See: http://anggtwu.net/2026-eev-gosse.html
 *  Author: Eduardo Ochs <eduardoochs@gmail.com>
 * Version: 2026sep17
 * License: GPL v2

** This is the simplest way to make the elisp
** hyperlinks to pages of the book work:
*
* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd /tmp/
wget -nc https://maxima-french-doc.fr/wp-content/uploads/2026/08/guide-maxima-equa-diff-en.pdf
*
* (code-pdf-page "gossegdem3" "/tmp/guide-maxima-equa-diff-en.pdf")
* (code-pdf-text "gossegdem3" "/tmp/guide-maxima-equa-diff-en.pdf")
** (find-gossegdem3page)
** (find-gossegdem3text)


 * Index:
 * «.1-introduction»	(to "1-introduction")
 * «.2-defining»	(to "2-defining")
 * «.3-checking»	(to "3-checking")
 * «.4-solving»		(to "4-solving")
 * «.5-particular-1»	(to "5-particular-1")
 * «.5.1-computing-1»	(to "5.1-computing-1")
 * «.5.2-ic1»		(to "5.2-ic1")
 * «.6-particular-2»	(to "6-particular-2")
 * «.6.1-computing-2»	(to "6.1-computing-2")
 * «.6.2-ic2»		(to "6.2-ic2")
 * «.6.3-bc2»		(to "6.3-bc2")
 * «.7-study»		(to "7-study")
 * «.7.1-directly»	(to "7.1-directly")
 * «.7.2-autonomous»	(to "7.2-autonomous")
 * «.7.3-separable»	(to "7.3-separable")
 * «.7.4-linear»	(to "7.4-linear")
 * «.8-direction»	(to "8-direction")
 * «.9-numerical»	(to "9-numerical")
 * «.9.1-eulers»	(to "9.1-eulers")
 * «.9.2-approximating»	(to "9.2-approximating")
 * «.9.3-plotting»	(to "9.3-plotting")
 * «.9.4-rk»		(to "9.4-rk")
 * «.10-desolve»	(to "10-desolve")
 * «.11-contrib_ode»	(to "11-contrib_ode")
*/




** «1-introduction»  (to ".1-introduction")
** (find-gossegdem3page 3 "1    Introduction")
** (find-gossegdem3text 3 "1    Introduction")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)


** «2-defining»  (to ".2-defining")
** (find-gossegdem3page 3 "2    Defining an ODE with Maxima")
** (find-gossegdem3text 3 "2    Defining an ODE with Maxima")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
'diff(y,x) = -y;
'diff(y(x),x) = -y(x);
'diff(y,x) + (1/(2*x))*y = 2;
'diff(y,x,2) + y = 0;
'diff(f,x,2) + 3*'diff(f,x) = k*f;


** «3-checking»  (to ".3-checking")
** (find-gossegdem3page 4 "3    Checking whether a function is a solution of an ODE")
** (find-gossegdem3text 4 "3    Checking whether a function is a solution of an ODE")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq: (1+x^2)*'diff(y,x) + 2*x*y = 4*x^3;
sol: y = (x^4+1)/(1+x^2);
verif: ev(eq, sol, diff);
ratsimp(verif);




** «4-solving»  (to ".4-solving")
** (find-gossegdem3page 6 "4    Solving an ODE with ode2, Maxima’s built-in solver")
** (find-gossegdem3text 6 "4    Solving an ODE with ode2, Maxima’s built-in solver")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq1  : 'diff(y,x) + 2*y = 6*x;
sol1 : ode2(eq1, y, x);
s1   : rhs(sol1)$
draw2d(
  xrange = [-2, 4],
  yrange = [-5, 12],
  xlabel = "x",
  ylabel = "y",
  title = "Solutions of the EDO for differents values of %c",
  color = red,    key = "%c = 0", explicit(subst(0, %c, s1), x, -3, 3),
  color = blue,   key = "%c = 1", explicit(subst(1, %c, s1), x, -3, 3),
  color = green,  key = "%c = 2", explicit(subst(2, %c, s1), x, -3, 3),
  color = orange, key = "%c = 3", explicit(subst(3, %c, s1), x, -3, 3),
  color = violet, key = "%c = 4", explicit(subst(4, %c, s1), x, -3, 3)  
)$



** «5-particular-1»  (to ".5-particular-1")
** (find-gossegdem3page 7 "5    Particular solution of a first-order ODE")
** (find-gossegdem3text 7 "5    Particular solution of a first-order ODE")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq  : 'diff(y,x) + 2*y = x$
sol : ode2(eq,y,x);
define(f(x), rhs(sol));
const : solve(f(0)=1, %c);
define(fp(x), subst(rhs(const[1]), %c, f(x)));
expand(fp(x));
draw2d(
    xrange = [-2, 4],
    yrange = [-1, 12],
    xlabel = "x",
    ylabel = "y",
    title = "Cauchy Problem dy/dx+2y=x et y(0)=1",
    color = red,    key = "%c =5/4", explicit(subst(5/4, %c, f(x)), x, -3, 3),
    color = blue,   key = "%c = 1 ", explicit(subst(  1, %c, f(x)), x, -3, 3),
    color = green,  key = "%c = 2 ", explicit(subst(  2, %c, f(x)), x, -3, 3),
    color = orange, key = "%c = 3 ", explicit(subst(  3, %c, f(x)), x, -3, 3),
    color = violet, key = "%c = 4 ", explicit(subst(  4, %c, f(x)), x, -3, 3),
    point_size=1, point_type=7, key="point (0,1)", color=black, points([[0,1]])
)$


** «5.1-computing-1»  (to ".5.1-computing-1")
** (find-gossegdem3page 8 "5.1    Computing a particular solution with Maxima")
** (find-gossegdem3text 8 "5.1    Computing a particular solution with Maxima")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq  : 'diff(y, x) + 2*y = x$
sol : ode2(eq, y, x);
define(f(x), rhs(sol));
const:solve(f(0)=1, %c);
define(fp(x), subst(rhs(const[1]), %c, f(x)));
expand(fp(x));


** «5.2-ic1»  (to ".5.2-ic1")
** (find-gossegdem3page 9 "5.2    Using Maxima’s built-in ic1 command")
** (find-gossegdem3text 9 "5.2    Using Maxima’s built-in ic1 command")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq2     : 'diff(y,x) - 3*y = 6*exp(x); y(0)=2;
solgen  : ode2(eq2, y, x);
solpart : ic1(solgen,x=0,y=2);



** «6-particular-2»  (to ".6-particular-2")
** (find-gossegdem3page 9 "6     Particular solution of a second-order ODE")
** (find-gossegdem3text 9 "6     Particular solution of a second-order ODE")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)

** «6.1-computing-2»  (to ".6.1-computing-2")
** (find-gossegdem3page 10 "6.1    Computing a particular solution with Maxima")
** (find-gossegdem3text 10 "6.1    Computing a particular solution with Maxima")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq : 'diff(y, x, 2) + y = 0; y(0) = 2; yprime(%pi/4) = 1;
sol_gen : ode2(eq, y, x);
define(f(x), rhs(sol_gen));
define(fprime(x), diff(f(x),x));
constantes : solve([f(0)=2, fprime(%pi/4)=1], [%k1, %k2]);
subst(constantes,f(x));



** «6.2-ic2»  (to ".6.2-ic2")
** (find-gossegdem3page 11 "6.2   Using Maxima’s built-in ic2 command")
** (find-gossegdem3text 11 "6.2   Using Maxima’s built-in ic2 command")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq       : 'diff(y,x,2) + 3*'diff(y,x) + 2*y = 0;
sol_gen  : ode2(eq, y, x);
sol_part : ic2(sol_gen, x=0, y=1, 'diff(y,x)=0);



** «6.3-bc2»  (to ".6.3-bc2")
** (find-gossegdem3page 11 "6.3   Using Maxima’s built-in bc2 command")
** (find-gossegdem3text 11 "6.3   Using Maxima’s built-in bc2 command")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq       : x^2*'diff(y,x,2) - 2*x*'diff(y,x) + 2*y = x^3;
sol_gen  : ode2(eq, y, x);
sol_bord : bc2(sol_gen, x=1, y=1, x=2, y=4);



** «7-study»  (to ".7-study")
** (find-gossegdem3page 12 "7     Study of some types of differential equations")
** (find-gossegdem3text 12 "7     Study of some types of differential equations")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)

** «7.1-directly»  (to ".7.1-directly")
** (find-gossegdem3page 12 "7.1    Directly integrable differential equation: y ′ = f (x)")
** (find-gossegdem3text 12 "7.1    Directly integrable differential equation: y ′ = f (x)")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
f(x)    := x^2 + cos(x);
eq      : 'diff(y, x) = f(x);
sol_gen : ode2(eq,y,x);
y = integrate(f(x),x) + %c;



** «7.2-autonomous»  (to ".7.2-autonomous")
** (find-gossegdem3page 13 "7.2    Autonomous differential equation y ′ = f (y)")
** (find-gossegdem3text 13 "7.2    Autonomous differential equation y ′ = f (y)")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq       : 'diff(y,x) = y*(1-y);
sol      : ode2(eq, y, x);
sol_simp : logcontract(sol);
sol_exp  : exp(lhs(sol_simp)) = exp(rhs(sol_simp));
sol_y    : solve(sol_exp, y);


** «7.3-separable»  (to ".7.3-separable")
** (find-gossegdem3page 13 "7.3    Separable differential equation: y ′ = f (y)g(x)")
** (find-gossegdem3text 13 "7.3    Separable differential equation: y ′ = f (y)g(x)")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq  : 'diff(y,x) = y*x;
sol : ode2(eq, y, x);

eq/y;
sol1 : integrate(1/y,y) = integrate(x,x)+K;
solve(sol1,y);

eq   : 'diff(y,x) = x/(1 + y^2);
sol  : ode2(eq, y, x);
sol2 : solve(sol,y)$sol2[3];

eq*(y^2+1);
sol3 : integrate(y^2+1,y) = integrate(x,x)+K;



** «7.4-linear»  (to ".7.4-linear")
** (find-gossegdem3page 15 "7.4    Linear differential equation y ′ = f (x)y + g(x)")
** (find-gossegdem3text 15 "7.4    Linear differential equation y ′ = f (x)y + g(x)")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
eq : 'diff(y,x) = x*y +x-1;
ode2(eq,y,x);


** «8-direction»  (to ".8-direction")
** (find-gossegdem3page 16 "8    Direction field of a first-order ODE")
** (find-gossegdem3text 16 "8    Direction field of a first-order ODE")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load(drawdf)$
drawdf(x - y, [x,-3,3], [y,-3,3])$


** «9-numerical»  (to ".9-numerical")
** (find-gossegdem3page 17 "9     Numerical approximation of a particular solution of an ODE")
** (find-gossegdem3text 17 "9     Numerical approximation of a particular solution of an ODE")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)

** «9.1-eulers»  (to ".9.1-eulers")
** (find-gossegdem3page 17 "9.1    Euler’s method for a first-order ODE")
** (find-gossegdem3text 17 "9.1    Euler’s method for a first-order ODE")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)

** «9.2-approximating»  (to ".9.2-approximating")
** (find-gossegdem3page 17 "9.2    Approximating a value of the particular solution")
** (find-gossegdem3text 17 "9.2    Approximating a value of the particular solution")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
/* Euler's method for y' = x - y, y(0) = 1 */
/* Parameters */
x0: 0$
y0: 1$
h: 1/100$
nsteps: 100$
/* Function f(x,y) = x - y */
f(x, y) := x - y$
/* Initialization */
x: x0$
y: y0$
/* Euler loop */
for i: 1 thru nsteps do (
    y: y + h * f(x, y),
    x: x + h
)$
/* Result: approximation of y(1) */
print("Approximation de y(1) par Euler :", float(y))$

kill(x, y)$
eq: 'diff(y,x) = x - y;
sol_exacte: ode2(eq, y, x);
sol_ci: ic1(sol_exacte, x=0, y=1);
y_exact: rhs(solve(sol_ci, y)[1]);
print("Valeur exacte y(1) :", ev(y_exact, x=1, numer))$



** «9.3-plotting»  (to ".9.3-plotting")
** (find-gossegdem3page 18 "9.3    Plotting a curve approximating a particular solution")
** (find-gossegdem3text 18 "9.3    Plotting a curve approximating a particular solution")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
x0: 0.0$ y0 : 1.0$ x_final : 2.0*%pi$ nsteps: 100$
h: float((x_final - x0) / nsteps)$
f(x, y) := float(cos(x) + y)$
x: x0$y: y0$
/* Lists to store the points */
X_list: [x]$
Y_list: [y]$
/* Euler loop */
for i: 1 thru nsteps do (
    y: y + h * f(x, y),    x: x + h,
    X_list: endcons(x, X_list),
    Y_list: endcons(y, Y_list)
)$
plot2d([discrete, X_list, Y_list],
    [style, [lines, 2, red]],
    [xlabel, "x"],
    [ylabel, "y"],
    [title, "Euler approximation for y' = cos(x) + y, y(0) = 1"],
    [legend, "Curve approximating the solution"]
)$


** «9.4-rk»  (to ".9.4-rk")
** (find-gossegdem3page 19 "9.4    Approximating a solution with the built-in rk command")
** (find-gossegdem3text 19 "9.4    Approximating a solution with the built-in rk command")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
rk(x - y, y, 1,[x, 0, 1, 0.4]);
listepoints : rk(x - y, y, 1,[x, 0, 1, 0.01])$
draw2d(
      title = "Approximation de la solution avec rk ",
      xlabel = "x",
      ylabel = "y",
      color = blue,
      point_type = filled_circle,
      point_size = 0.3,
      line_width = 2,
      points_joined = true,
      points(listepoints)
)$

** «10-desolve»  (to ".10-desolve")
** (find-gossegdem3page 20 "10    The built-in desolve command")
** (find-gossegdem3text 20 "10    The built-in desolve command")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
de     : 'diff(y(x), x) + y(x) = exp(-x);
sol    : desolve(de, y(x));
sol_ci : ev(sol, y(0) = 2);

atvalue(y(x), x = 0, 1)$
atvalue('diff(y(x), x), x = 0, 0)$
de2  : 'diff(y(x), x, 2) - y(x) = exp(x);
sol2 : desolve(de2, y(x));

atvalue(x(t), t=0, 1)$
atvalue(y(t), t=0, 0)$
eq1  : 'diff(x(t),t) = x(t) + y(t);
eq2  : 'diff(y(t),t) = 4*x(t) - 2*y(t);
sol3 : desolve([eq1,eq2], [x(t),y(t)]);



** «11-contrib_ode»  (to ".11-contrib_ode")
** (find-gossegdem3page 22 "11     Going further: the contrib_ode package")
** (find-gossegdem3text 22 "11     Going further: the contrib_ode package")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load(contrib_ode)$
eq: x*'diff(y,x)^2 - (1+x*y)*'diff(y,x) + y = 0;
ode2(eq,y,x);
contrib_ode(eq,y,x);
ode_check(eq,[y=log(x)]);

eq2: 'diff(y,x) = y^2 - 2*x*y + x^2 + 1;
contrib_ode(eq2, y, x);

eq3: (x^2 + 1)*'diff(y,x,2) + x*'diff(y,x) - y = 0;
sol3: odelin(eq3, y, x);

sol4:listify(sol3);
y=%k1*sol4[1]+%k2*sol4[2];




/*
 * Local Variables:
 * coding:  utf-8-unix
 * End:
*/