(1) imagpart(first(s)) isn't a boolean; let me guess that you want something like
if equal(imagpart(first(s)),0) then ...
(2) The for s in soln ... loop only returns only the last matching solution, but two of thee solutions satisfy the condition.
Surely this isn't what you want.
(3) You might try filtering the solutions with something like
map(lambda([s], (s : first(s), if equal(imagpart(rhs(s)),0) and is(ddf(rhs(s))<0) then [s] else %union())),soln);
The ev you included isn't needed.
--Barton
________________________________________
From: maxima-bounces at math.utexas.edu [maxima-bounces at math.utexas.edu] on behalf of Thomas D. Dean [tomdean at speakeasy.org]
Sent: Tuesday, April 09, 2013 20:47
To: maxima
Subject: Convert %union(...) to list
kill(all);
load(to_poly_solve);
declare(a,scalar);
assume(a>0);
eq1:h=sqrt(a^2-r^2)+a;
eq2:%pi*r^2*h/3;
define(f(r),subst(eq1,eq2));
define(df(r),diff(f(r),r,1));
define(ddf(r),diff(df(r),r,1));
soln:to_poly_solve(df(r)=0,r);
for s in soln do (
if imagpart(first(s)) then (
if ev(ddf(rhs(first(s))))<0 then (
soln_r:s
)
)
)$
print("Volume",f(rhs(first(soln_r))))$
soln is %union([r = 0],[r = -2^(3/2)*a/3],[r = 2^(3/2)*a/3])
I want
[r = 0,r = -2^(3/2)*a/3,r = 2^(3/2)*a/3]
Is there an easier way than
l:makelist();
for s in soln do l:[l,s];
l:flatten(l);
Tom Dean
_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima