Ask Your Question
1

How to substitute realpart and imagpart after conversion to rectform?

asked 2013-02-27 11:00:23 +0200

ximeg gravatar image

updated 2013-02-27 11:05:19 +0200

Hello, I need to split some complicated expression into real and imaginary part, and I use function "rectform()" to do it. Then I want to plot just the imaginary part of the expression, and it seems obvious to substitute zero in place of real part. However, the substitution does not work.

Here is a minimal example, which reproduces this behavior. I want to substitute $\Re [A]$ with "$x$":

sage: var("A, x")
-> (A, x)
sage: assume(A, "complex")
sage: Ar = A.rectform()
sage: print Ar
-> realpart(A) + I*imagpart(A)

Then we try to substitute $\Re[x] \to x$:

sage: Ar.subs({real(A): x})
-> realpart(A) + I*imagpart(A)    # No effect
sage: Ar.subs({real_part(A): x})
-> realpart(A) + I*imagpart(A)    # No effect
sage: Ar.subs({A.real(): x})
-> realpart(A) + I*imagpart(A)    # No effect
sage: Ar.subs({A.real_part(): x})
-> realpart(A) + I*imagpart(A)    # No effect
sage: Ar.subs({realpart(A): x})
-> NameError: name 'realpart' is not defined
sage: Ar.subs({A.realpart(): x})
-> AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'realpart'

Then I try to use interface to maxima:

sage: maxima.subst(x, realpart(A), Ar)
-> NameError: name 'realpart' is not defined
sage: maxima.subst(x, real(A), Ar)
-> 'realpart(x)+%i*'imagpart(x)    # Wrong substitution
sage: maxima.subst(x, A.realpart(), Ar)
-> AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'realpart'
sage: maxima.subst(x, A.real(), Ar)
-> 'realpart(x)+%i*'imagpart(x)    # Wrong substitution

As you can see, maxima replaces $A$ with $x$ in the whole expression. E.g., if $x=0$, then after the substitution the whole expression is zero, not just the real part. How to do the substitution? Are there any workarounds?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-02-27 13:06:01 +0200

calc314 gravatar image

updated 2013-02-27 13:10:00 +0200

In Sage 5.0, I'm not getting access to rectform as part of the object A here. The following works for me:

var('A x')
assume(A,"complex")
ar=real_part(A)+I*imag_part(A)
ar.subs(real_part(A)==x)

x + I*imag_part(A)

Also, the substitution with a dictionary works for me.

ar.subs({real_part(A):x})

x + I*imag_part(A)

In Sage 5.3, I'm getting access to rectform, and I have the difficulty you are having with realpart. I think it's got to be the difference between realpart and real_part.

Perhaps someone here has insight into the differences.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-02-27 11:00:23 +0200

Seen: 593 times

Last updated: Feb 27 '13