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 10:29:48 -0500
The simple answer is that solve ignores real/complex declarations.
Clearly that's not good, but I don't think anyone is currently working
on fixing it. There are some workarounds, though.
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.
> (%i66) solve([imagpart(%),realpart(%)],[L,C]);
> (%o66) [[L=-sqrt(11)/(400000*%pi),C=-sqrt(11)/(12000000000*%
> pi)],[L=sqrt(11)/(400000*%pi),C=sqrt(11)/(12000000000*%pi)]]
Nice trick, but unfortunately, it doesn't work in general. For example:
eq: L^2=-C^2$
solve([realpart(eq),imagpart(eq)],[L,C]) =>
[[L = %r4,C = %i*%r4],[L = %r5,C = -%i*%r5]]
Where the only real solution is L=0, C=0. I can't think of any good
way to force only real solutions. Something like the following is
probably a better approximation, but I suspect it, too, will fail in
some cases, because solve doesn't know that the solution for
realpart(L) must itself be real!
declare([L,C],complex)$
%rnum_list: []$ /* need to include any generated %rnums below */
sols: solve(eq,[L,C])$
sol1: sols[1]$ /* in real use, we'd loop over
solutions, but I'm keeping it simple */
solve(append(realpart(sol1),imagpart(sol1),[imagpart(L)=0,imagpart(C)=0]),
append(%rnum_list,[realpart(L),imagpart(L),realpart(C),imagpart(C)]));
I'm not sure how you could package this as a function cleanly, because
I don't think there is any way to make declarations local.... And
there are other problems along the way (I tried)....
Let us know how this approach works for you.
-s