Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: How do I get Real and imaginary parts of a symbolic expression?
Date: Fri, 4 Jul 2008 11:42:01 +0000 (UTC)
Organization: TUD
Lines: 37
Message-ID: <g4l2a9$aee$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1215171721 10702 172.30.248.37 (4 Jul 2008 11:42:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 4 Jul 2008 11:42:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1420673
Xref: news.mathworks.com comp.soft-sys.matlab:477528



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 I got instead :
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 I cannot simplify them 
to obtain the answers I listed above. Can anyone help me 
out of this?


Thanks

ES