Should solve try and equate realparts and imaginary parts of equations?
Subject: Should solve try and equate realparts and imaginary parts of equations?
From: Stavros Macrakis
Date: Wed, 12 Dec 2007 11:22:27 -0500
On Dec 12, 2007 2:52 AM, Rob Frohne <frohro at wallawalla.edu> wrote:
> I'm playing with Maxima and complex equations and am wondering why solve
> doesn't break up the complex equation into its real and imaginary parts.
Try the following code and see if it works for you. It takes a list
of equations and a list of variables and tries to return only
solutions where the variables are real-valued. It may ask questions
about the sign of parameters or even variables.
/* doesn't work */
solve_real ( eqs, vars ) :=
block( [%rnum_list: [], sols ],
apply( 'declare, [vars, 'complex] ), /* Yuck */
sols: xreduce('append,
makelist(
solve_list(
append( map(realpart, soln),
map(imagpart, soln),
map(imagpart, vars)),
append( map(realpart, vars),
map(imagpart, vars),
%rnum_list ) ),
soln,
solve_list( eqs, vars) )),
makelist( delete('delete_me, q),
q,
subst( append( makelist( (imagpart(v)=0)='delete_me, v, vars),
makelist( realpart(v) = v, v, vars) ),
sols)))$
/* Uniformly return a list of solutions */
solve_list(eqs, vars) :=
block([sols, solve_inconsistent_error: false],
sols : solve(eqs,vars),
if sols='ALL then []
elseif sols=[] or listp(sols[1]) then sols
else map("[",sols))$
Example:
solve_real([x^2=a*y^2],[x,y]);
Is a positive, negative, or zero?
n;
Dependent equations eliminated: (5)
Dependent equations eliminated: (5)
[[x = 0,y = 0,delete_me,%r52 = 0,%r53 = %r54]]
(There is a bug in the delete function which leaves some instances
behind. This should get fixed soon.)
Let us know how this works for you.
-s