Solving 3rd order equation by solve.



Pepe Sanchez <jose.sanchez at uv.es> writes:
>> I want to know general methods to avoid a small imaginary error.
>
> I guess that you need something similar to the "chop" operator in
> Mathematica.
>   

The same idea as Pepe suggested, but maybe nicer than operating in place
on s:

(%i1) fpprintprec: 5$

(%i2) s: float(rectform(solve(x^3-3*x^2-2*x+1,x)))$

(%i3) chop (x, eps) := if is (imagpart (x) < eps) then realpart (x) else x$

(%i4) chopeq (eq, eps) := chop (lhs (eq), eps) = chop (rhs (eq), eps)$

(%i5) map (lambda ([eq], chopeq (eq, 1e-8)), s);
(%o5)               [x = .34338, x = - .83424, x = 3.4909]

Here, chopeq could have been written with a call to map as well, but
since there are only two elements (lhs and rhs), I thought this was
easier to read.

Rupert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20130226/933f499d/attachment-0001.pgp>;