Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
symbolic variables and complex numbers

Subject: symbolic variables and complex numbers

From: Uwe Brauer

Date: 14 Jun, 2013 08:29:08

Message: 1 of 10

Hello

I hope this time I read the documentation carefully enough. I would like to perform symbolic operations with complex numbers. Here is an example

 syms phi
 z=cos(phi)+imag(sin(phi))
 abs(z)
 now I hoped matlab would return 1, but it did not instead I saw.
abs(cos(phi)-1/2*i*sin(phi)+1/2*i*sin(abs(phi)^2/phi))

Is there anyway that matlab would return

 p=abs(z)
 p=1

Thanks

Uwe Brauer

Subject: symbolic variables and complex numbers

From: Torsten

Date: 14 Jun, 2013 08:52:09

Message: 2 of 10

"Uwe Brauer" wrote in message <kpek8k$eu9$1@newscl01ah.mathworks.com>...
> Hello
>
> I hope this time I read the documentation carefully enough. I would like to perform symbolic operations with complex numbers. Here is an example
>
> syms phi
> z=cos(phi)+imag(sin(phi))
> abs(z)
> now I hoped matlab would return 1, but it did not instead I saw.
> abs(cos(phi)-1/2*i*sin(phi)+1/2*i*sin(abs(phi)^2/phi))
>
> Is there anyway that matlab would return
>
> p=abs(z)
> p=1
>
> Thanks
>
> Uwe Brauer

imag(sin(phi)) = 0, so the result should be abs(cos(phi)).
You should get this result using
simplify(abs(cos(phi)-1/2*i*sin(phi)+1/2*i*sin(abs(phi)^2/phi))).
Maybe you meant
z=cos(phi)+i*sin(phi) ?

Best wishes
Torsten.

Subject: symbolic variables and complex numbers

From: Uwe Brauer

Date: 14 Jun, 2013 09:17:11

Message: 3 of 10

"Torsten" wrote in message <kpeljp$i6p$1@newscl01ah.mathworks.com>...

> > Uwe Brauer
>
> imag(sin(phi)) = 0, so the result should be abs(cos(phi)).
> You should get this result using
> simplify(abs(cos(phi)-1/2*i*sin(phi)+1/2*i*sin(abs(phi)^2/phi))).
> Maybe you meant
> z=cos(phi)+i*sin(phi) ?
>
> Best wishes
> Torsten.

well I meant
z=cos(phi)+i*sin(phi)

However then Matlab returns only abs(cos(phi)+i*sin(phi))
which is not helpful.

That is why I thought Imag means i*sin(phi), but no (I did not check carefully enough the doc): for a given complex number imag returns the imaginary part.

But back to my original question it seems that matlab cannot calculate the absolute value of a complex function symbolically.

Subject: symbolic variables and complex numbers

From: Torsten

Date: 14 Jun, 2013 09:35:09

Message: 4 of 10

"Uwe Brauer" wrote in message <kpen2n$l45$1@newscl01ah.mathworks.com>...
> "Torsten" wrote in message <kpeljp$i6p$1@newscl01ah.mathworks.com>...
>
> > > Uwe Brauer
> >
> > imag(sin(phi)) = 0, so the result should be abs(cos(phi)).
> > You should get this result using
> > simplify(abs(cos(phi)-1/2*i*sin(phi)+1/2*i*sin(abs(phi)^2/phi))).
> > Maybe you meant
> > z=cos(phi)+i*sin(phi) ?
> >
> > Best wishes
> > Torsten.
>
> well I meant
> z=cos(phi)+i*sin(phi)
>
> However then Matlab returns only abs(cos(phi)+i*sin(phi))
> which is not helpful.
>
> That is why I thought Imag means i*sin(phi), but no (I did not check carefully enough the doc): for a given complex number imag returns the imaginary part.
>
> But back to my original question it seems that matlab cannot calculate the absolute value of a complex function symbolically.

And
simplify(abs(cos(phi)+1i*sin(phi)))
does not give you 1 ?

Best wishes
Torsten.

Subject: symbolic variables and complex numbers

From: Uwe Brauer

Date: 14 Jun, 2013 10:05:09

Message: 5 of 10

"Torsten" wrote in message <kpeo4d$n7i$1@newscl01ah.mathworks.com>...
> "Uwe Brauer" wrote in message <kpen2n$l45$1@newscl01ah.mathworks.com>...
> > "Torsten" wrote in message <kpeljp$i6p$1@newscl01ah.mathworks.com>...
>
> And
> simplify(abs(cos(phi)+1i*sin(phi)))
> does not give you 1 ?

Not in my version, does it for you??

Subject: symbolic variables and complex numbers

From: Torsten

Date: 14 Jun, 2013 10:40:09

Message: 6 of 10

"Uwe Brauer" wrote in message <kpepsl$qqg$1@newscl01ah.mathworks.com>...
> "Torsten" wrote in message <kpeo4d$n7i$1@newscl01ah.mathworks.com>...
> > "Uwe Brauer" wrote in message <kpen2n$l45$1@newscl01ah.mathworks.com>...
> > > "Torsten" wrote in message <kpeljp$i6p$1@newscl01ah.mathworks.com>...
> >
> > And
> > simplify(abs(cos(phi)+1i*sin(phi)))
> > does not give you 1 ?
>
> Not in my version, does it for you??

It does in Mathematica :-(

Try
http://www.wolframalpha.com
and insert
simplify(abs(cos(phi)+1i*sin(phi)))

Best wishes
Torsten.

Subject: symbolic variables and complex numbers

From: Uwe Brauer

Date: 14 Jun, 2013 10:48:07

Message: 7 of 10

"Torsten" wrote in message <kperu9$1lq$1@newscl01ah.mathworks.com>...
> "Uwe Brauer" wrote in message <kpepsl$qqg$1@newscl01ah.mathworks.com>...
> > "Torsten" wrote in message <kpeo4d$n7i$1@newscl01ah.mathworks.com>...
> > > "Uwe Brauer" wrote in message <kpen2n$l45$1@newscl01ah.mathworks.com>...
> > > > "Torsten" wrote in message <kpeljp$i6p$1@newscl01ah.mathworks.com>...
> > >
> > > And
> > > simplify(abs(cos(phi)+1i*sin(phi)))
> > > does not give you 1 ?
> >
> > Not in my version, does it for you??
>
> It does in Mathematica :-(
>
> Try
> http://www.wolframalpha.com
> and insert
> simplify(abs(cos(phi)+1i*sin(phi)))
>
> Best wishes
> Torsten.


Unfortunately I don't have access to mathematica! So it does not work in Matlab?

Subject: symbolic variables and complex numbers

From: Torsten

Date: 14 Jun, 2013 11:03:08

Message: 8 of 10

"Uwe Brauer" wrote in message <kpesd7$2nv$1@newscl01ah.mathworks.com>...
> "Torsten" wrote in message <kperu9$1lq$1@newscl01ah.mathworks.com>...
> > "Uwe Brauer" wrote in message <kpepsl$qqg$1@newscl01ah.mathworks.com>...
> > > "Torsten" wrote in message <kpeo4d$n7i$1@newscl01ah.mathworks.com>...
> > > > "Uwe Brauer" wrote in message <kpen2n$l45$1@newscl01ah.mathworks.com>...
> > > > > "Torsten" wrote in message <kpeljp$i6p$1@newscl01ah.mathworks.com>...
> > > >
> > > > And
> > > > simplify(abs(cos(phi)+1i*sin(phi)))
> > > > does not give you 1 ?
> > >
> > > Not in my version, does it for you??
> >
> > It does in Mathematica :-(
> >
> > Try
> > http://www.wolframalpha.com
> > and insert
> > simplify(abs(cos(phi)+1i*sin(phi)))
> >
> > Best wishes
> > Torsten.
>
>
> Unfortunately I don't have access to mathematica! So it does not work in Matlab?

Unfortunately, I don't have access to MATLAB.
Maybe somebody else can test ...

Best wishes
Torsten.

Subject: symbolic variables and complex numbers

From: Alan_Weiss

Date: 14 Jun, 2013 12:56:08

Message: 9 of 10

On 6/14/2013 5:17 AM, Uwe Brauer wrote:
> "Torsten" wrote in message <kpeljp$i6p$1@newscl01ah.mathworks.com>...
>
>> > Uwe Brauer
>> imag(sin(phi)) = 0, so the result should be abs(cos(phi)).
>> You should get this result using
>> simplify(abs(cos(phi)-1/2*i*sin(phi)+1/2*i*sin(abs(phi)^2/phi))).
>> Maybe you meant z=cos(phi)+i*sin(phi) ?
>>
>> Best wishes
>> Torsten.
>
> well I meant z=cos(phi)+i*sin(phi)
> However then Matlab returns only abs(cos(phi)+i*sin(phi))
> which is not helpful.
>
> That is why I thought Imag means i*sin(phi), but no (I did not check
> carefully enough the doc): for a given complex number imag returns the
> imaginary part.
> But back to my original question it seems that matlab cannot calculate
> the absolute value of a complex function symbolically.

There are two problems. The main one is that you did not assume that phi
was real. If phi is complex, then abs(cos(phi) + i*sin(phi)) is not one.

Try the following:

syms phi real
z = abs(cos(phi) + i*sin(phi))
y = simplify(z,'Steps',100)

I get the following result:

y =

1

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: symbolic variables and complex numbers

From: Uwe Brauer

Date: 14 Jun, 2013 13:16:08

Message: 10 of 10

Alan_Weiss <aweiss@mathworks.com> wrote in message <kpf3t8$kgd$1@newscl01ah.mathworks.com>...
> On 6/14/2013 5:17 AM, Uwe Brauer wrote:
> > "Torsten" wrote in message <kpeljp$i6p$1@newscl01ah.mathworks.com>...
>
> There are two problems. The main one is that you did not assume that phi
> was real. If phi is complex, then abs(cos(phi) + i*sin(phi)) is not one.

Ah, I did not think about that.

>
> Try the following:
>
> syms phi real
> z = abs(cos(phi) + i*sin(phi))
> y = simplify(z,'Steps',100)

Ok, this is a new option in simplify!? my version from 2008 does not have it, in any case, even a simple
y = simplify(z)

Does the job, thanks!!!

Tags for this Thread

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.

Contact us