In general these do not avoid a small imaginary "error", but set
the imaginary part to zero if it is less than a certain absolute value.
You might consider that 10.0d-10 + %i* 9.0d0-5 should probably NOT
be chopped to 10.0d-10, even though the imaginary part is less than
eps=10.0d-5.
You might prefer to use "relative error" for example.
RJF
On 2/26/2013 3:26 AM, Rupert Swarbrick wrote:
> 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
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima