Separable ODEs

Separable ODEs are the most important and frequently encountered class of first-order differential equations. MathHook provides a robust solver that handles both general and particular solutions with automatic variable separation and symbolic integration.

📐

Mathematical Definition

A first-order ODE

dydx=f(x,y)\frac{dy}{dx} = f(x,y)
is separable if it can be written as:

dydx=g(x)h(y)\frac{dy}{dx} = g(x) \cdot h(y)

where g(x)g(x) is a function of only xx and h(y)h(y) is a function of only yy.

Code Examples

Simple Linear ODE

Solve dy/dx = x

use mathhook::prelude::*;
use mathhook::ode::first_order::separable::SeparableODESolver;

let x = symbol!(x);
let y = symbol!(y);
let solver = SeparableODESolver::new();

let solution = solver.solve(&expr!(x), &y, &x, None)?;
// Result: y = x²/2 + C

Exponential Growth

Solve dy/dx = y (exponential growth/decay model)

use mathhook::prelude::*;
use mathhook::ode::first_order::separable::SeparableODESolver;

let x = symbol!(x);
let y = symbol!(y);
let solver = SeparableODESolver::new();

let solution = solver.solve(&expr!(y), &y, &x, None)?;
// Result: y = Ce^x

Product Form

Solve dy/dx = xy (nonlinear growth model)

use mathhook::prelude::*;
use mathhook::ode::first_order::separable::SeparableODESolver;

let x = symbol!(x);
let y = symbol!(y);
let solver = SeparableODESolver::new();

let solution = solver.solve(&expr!(x * y), &y, &x, None)?;
// Result: y = Ce^(x²/2)

Initial Value Problem

Solve dy/dx = x with y(0) = 1

use mathhook::prelude::*;
use mathhook::ode::first_order::separable::SeparableODESolver;

let x = symbol!(x);
let y = symbol!(y);
let solver = SeparableODESolver::new();

let ic = Some((expr!(0), expr!(1))); // y(0) = 1
let solution = solver.solve(&expr!(x), &y, &x, ic)?;
// Result: y = x²/2 + 1

Rational Function

Solve dy/dx = x/y

use mathhook::prelude::*;
use mathhook::ode::first_order::separable::SeparableODESolver;

let x = symbol!(x);
let y = symbol!(y);
let solver = SeparableODESolver::new();

let rhs = expr!(x / y);
let solution = solver.solve(&rhs, &y, &x, None)?;
// Result: y² - x² = C (implicit) or y = ±√(x² + C) (explicit)

🔗 Related Topics