<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172029</link>
    <title>MATLAB Central Newsreader - Real and imaginary parts of symbolic expression</title>
    <description>Feed for thread: Real and imaginary parts of symbolic expression</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 04 Jul 2008 07:55:05 -0400</pubDate>
      <title>Real and imaginary parts of symbolic expression</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172029#441134</link>
      <author>Emeka Obe</author>
      <description>Dear All,&lt;br&gt;
&lt;br&gt;
I experience a problem getting the real and imaginary parts &lt;br&gt;
of a complex expression in symbolic form.&lt;br&gt;
For example I have this code and will like to know how to &lt;br&gt;
get the real and imaginary parts:&lt;br&gt;
&lt;br&gt;
clear; clc;&lt;br&gt;
syms x y n&lt;br&gt;
z=n*cos(x)+i*y*sin(x);&lt;br&gt;
r = real(z);&lt;br&gt;
m = imag(z);&lt;br&gt;
&lt;br&gt;
The expressions I expected to get were:&lt;br&gt;
r = n*cos(x) and&lt;br&gt;
m = y*sin(x).&lt;br&gt;
&lt;br&gt;
But instead I get:&lt;br&gt;
r =&lt;br&gt;
&amp;nbsp;&lt;br&gt;
1/2*n*cos(x)+1/2*i*y*sin(x)+1/2*conj(n*cos(x)+i*y*sin(x))&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;and&lt;br&gt;
&lt;br&gt;
m =&lt;br&gt;
&amp;nbsp;&lt;br&gt;
-1/2*i*(n*cos(x)+i*y*sin(x)-conj(n*cos(x)+i*y*sin(x)))&lt;br&gt;
&lt;br&gt;
Though these are correct, I cannot they are more &lt;br&gt;
complicated and I cannot simplify them to obtain the &lt;br&gt;
answers I listed above. Can anyone help me out of this?&lt;br&gt;
I need to have a way of obtaining the real and imaginary &lt;br&gt;
parts of any arbitrary complex expression is the actual &lt;br&gt;
form without having longer expressions.&lt;br&gt;
&lt;br&gt;
Thanks&lt;br&gt;
&lt;br&gt;
ES</description>
    </item>
    <item>
      <pubDate>Fri, 04 Jul 2008 17:21:42 -0400</pubDate>
      <title>Re: Real and imaginary parts of symbolic expression</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172029#441220</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;g4kl0p$k1c$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
Emeka Obe &amp;lt;obeway@gmail.com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt;I experience a problem getting the real and imaginary parts &lt;br&gt;
&amp;gt;of a complex expression in symbolic form.&lt;br&gt;
&amp;gt;For example I have this code and will like to know how to &lt;br&gt;
&amp;gt;get the real and imaginary parts:&lt;br&gt;
&lt;br&gt;
&amp;gt;clear; clc;&lt;br&gt;
&amp;gt;syms x y n&lt;br&gt;
&amp;gt;z=n*cos(x)+i*y*sin(x);&lt;br&gt;
&amp;gt;r = real(z);&lt;br&gt;
&lt;br&gt;
&amp;gt;The expressions I expected to get were:&lt;br&gt;
&amp;gt;r = n*cos(x) and&lt;br&gt;
&lt;br&gt;
&amp;gt;But instead I get:&lt;br&gt;
&amp;gt;r =&lt;br&gt;
&lt;br&gt;
&amp;gt;1/2*n*cos(x)+1/2*i*y*sin(x)+1/2*conj(n*cos(x)+i*y*sin(x))&lt;br&gt;
&lt;br&gt;
The output you received is correct, and your expected output is not.&lt;br&gt;
&lt;br&gt;
Your variable y is symbolic, so the program is to produce the general&lt;br&gt;
output for all possible values the symbol y could assume. That&lt;br&gt;
output is for real() is *not* n*cos(x) . Simple proof: suppose y was 5*i .&lt;br&gt;
real(n*cos(x) + i*i*5*sin(x)) is real(n*cos(x) - 5*sin(x))&lt;br&gt;
which is different than your proposed answer of n*cos(x) .&lt;br&gt;
&lt;br&gt;
The hidden assumption in your proposed expression is that none of&lt;br&gt;
n, x, or y are complex: if any of them are complex then your&lt;br&gt;
proposed output is incorrect. If that assumption is in fact valid&lt;br&gt;
for your problem domain, then in order to have your proposed output&lt;br&gt;
appear automatically, tell matlab about those assumptions.&lt;br&gt;
&lt;br&gt;
I do not have the symbolic toolbox, so I do not know what the&lt;br&gt;
syntax is for providing assumptions. In the base Maple engine&lt;br&gt;
which underlies the symbolic toolbox, the way I would code would be&lt;br&gt;
(in Maple code!):&lt;br&gt;
&lt;br&gt;
z := n*cos(x) + I*y*sin(x);&lt;br&gt;
r := Re(z) assuming real;&lt;br&gt;
m := Im(z) assuming real;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&quot;There is no greater calling than to serve your fellow men.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;There is no greater contribution than to help the weak.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;There is no greater satisfaction than to have done it well.&quot;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-- Walter Reuther</description>
    </item>
    <item>
      <pubDate>Tue, 08 Jul 2008 14:49:31 -0400</pubDate>
      <title>Re: Real and imaginary parts of symbolic expression</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172029#441826</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Walter Roberson&quot; &amp;lt;roberson@ibd.nrc-cnrc.gc.ca&amp;gt; wrote in message &lt;br&gt;
news:g4lm76$q9h$1@canopus.cc.umanitoba.ca...&lt;br&gt;
&amp;gt; In article &amp;lt;g4kl0p$k1c$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
&amp;gt; Emeka Obe &amp;lt;obeway@gmail.com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
*snip*&lt;br&gt;
&lt;br&gt;
&amp;gt; I do not have the symbolic toolbox, so I do not know what the&lt;br&gt;
&amp;gt; syntax is for providing assumptions. In the base Maple engine&lt;br&gt;
&amp;gt; which underlies the symbolic toolbox, the way I would code would be&lt;br&gt;
&amp;gt; (in Maple code!):&lt;br&gt;
&lt;br&gt;
The syntax for assuming that x, y, and n are real symbolic variables is:&lt;br&gt;
&lt;br&gt;
syms x y n real&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
  </channel>
</rss>

