Thread Subject: How do I get Real and imaginary parts of a symbolic expression?

Subject: How do I get Real and imaginary parts of a symbolic expression?

From: Emeka Obe

Date: 4 Jul, 2008 11:42:01

Message: 1 of 1

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

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com