Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Real and imaginary parts of symbolic expression
Date: Fri, 4 Jul 2008 07:55:05 +0000 (UTC)
Organization: TUD
Lines: 42
Message-ID: <g4kl0p$k1c$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1215158105 20524 172.30.248.38 (4 Jul 2008 07:55:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 4 Jul 2008 07:55:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1420673
Xref: news.mathworks.com comp.soft-sys.matlab:477488



Dear All,

I experience a problem getting the real and imaginary parts 
of a complex expression in symbolic form.
For example I have this code and will like to know how to 
get the real and imaginary parts:

clear; clc;
syms x y n
z=n*cos(x)+i*y*sin(x);
r = real(z);
m = imag(z);

The expressions I expected to get were:
r = n*cos(x) and
m = y*sin(x).

But instead I get:
r =
 
1/2*n*cos(x)+1/2*i*y*sin(x)+1/2*conj(n*cos(x)+i*y*sin(x))
 
 and

m =
 
-1/2*i*(n*cos(x)+i*y*sin(x)-conj(n*cos(x)+i*y*sin(x)))

Though these are correct, I cannot they are more 
complicated and I cannot simplify them to obtain the 
answers I listed above. Can anyone help me out of this?
I need to have a way of obtaining the real and imaginary 
parts of any arbitrary complex expression is the actual 
form without having longer expressions.

Thanks

ES