1
Cordial solve
jess edited this page 2026-04-15 09:38:07 -07:00
Cordial: solve!
Math form
let solve_for_l(f0, c) = l where lc_freq(l, c) = f0
Macro form
let solve_for_l = solve!(l, lc_freq)
let solve_for_l = solve!(l from lc_freq)
Featured example — LC tank inversion
use spice
// In Cordial, types can be arbitrary and are therefore assumed to be units
// when `use spice` is active. Hz, F, H are recognised ECE units; you could
// equally write `x: C` for Coulombs and the unit gets appended.
fn L(f: Hz, c: F) -> H {
return 1 / (((2pi * f)^2) * c)
}
// Math form: reads as an equation, mirrors how you'd write the algebra.
let fx(L, c) = f where L(f, c) = L
// Macro form: cleaner shorthand. Same result.
let f0 = solve!(f, L)
/= L(1000, 22n)
→ 1.15H
/= f0(1.15H, 22n)
→ ~1000
Solver parameters
| Guard | Limit |
|---|---|
| Newton iterations | 100 |
| Convergence epsilon | 1e-10 |
| Initial guess | 1.0 |
| Damping | step-halving on NaN / Inf / error |
Limits
- Single variable.
- Continuous, differentiable source function.
- Symbolic inversion not implemented — numerical backend only.
See also
Acord
The editor
Cordial
Power tools
Contributors