cubicroots.m
USAGE: [x1, x2, x3] = cubicroots(a, b, c, d)
PURPOSE: Find the roots to the cubic equation:
a*x^3 + b*x^2 + c*x + d = 0
Can also be used with a = 0 and/or b = 0
INPUTS: a, b, c, d - may be 1 arbitrary size in a mix with scalars
OUTPUTS: The roots such that:
(x-x1)*(x-x2)*(x-x3) = x^3 + b/a*x^2 + c/a*x + d/a
If a == 0 then x3 is nan since polynomial is 2:nd degree
If also b == 0 then x2 will also be nan
If also c == 0 then x1 will also be nan
NOTES: Faster than the function roots, in particular when several
equations solved at once. Also more accurate than roots
Solutions are in the same order as from function roots
If a ~= 0, x1 is always real
cubicroots(a,b,c,d,n) iterates n times to reduce tiny errors
Dependencies