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:
Real/Imaginary Part complex Numbers

Subject: Real/Imaginary Part complex Numbers

From: matt reister

Date: 9 Feb, 2009 09:38:02

Message: 1 of 3

I am trying to take the real and imaginary part of a number. I can easily see what they are by inspection but i am trying to get matlab to tell me and its giving me crazy results.

Here is my code
L = 8.5*10^-6;
C = 1200*10^-12;
Rs = 330;
R0 = 50;
syms Ri
W = 1/sqrt(L*C);


Zl_Denom = 1 - W^2*L*C + i*(W*Ri*L)
real_Zl_Denom = real(Zl_Denom)

Here is the output i receive:

Zl_Denom =
 
1/9007199254740992+13336086976169431513353727219037/158456325028528675187087900672*i*Ri
 
 
 
real_Zl_Denom =
 
1/9007199254740992+13336086976169431513353727219037/316912650057057350374175801344*i*Ri-13336086976169431513353727219037/316912650057057350374175801344*i*conj(Ri)

Is the reason its not returning the real part how i want it i.e. the value of 1 - W^2*L*C is because i have Ri defined as syms?

Thank you in advance.......
Still learning......

Subject: Real/Imaginary Part complex Numbers

From: Joerg Buchholz

Date: 9 Feb, 2009 12:27:02

Message: 2 of 3

"matt reister" <mattreister@hotmail.com> wrote in message <gmothp$2gr$1@fred.mathworks.com>...
> I am trying to take the real and imaginary part of a number. I can easily see what they are by inspection but i am trying to get matlab to tell me and its giving me crazy results.
>
> Here is my code
> L = 8.5*10^-6;
> C = 1200*10^-12;
> Rs = 330;
> R0 = 50;
> syms Ri
> W = 1/sqrt(L*C);
>
>
> Zl_Denom = 1 - W^2*L*C + i*(W*Ri*L)
> real_Zl_Denom = real(Zl_Denom)
>
> Here is the output i receive:
>
> Zl_Denom =
>
> 1/9007199254740992+13336086976169431513353727219037/158456325028528675187087900672*i*Ri
>
>
>
> real_Zl_Denom =
>
> 1/9007199254740992+13336086976169431513353727219037/316912650057057350374175801344*i*Ri-13336086976169431513353727219037/316912650057057350374175801344*i*conj(Ri)
>
> Is the reason its not returning the real part how i want it i.e. the value of 1 - W^2*L*C is because i have Ri defined as syms?
>
> Thank you in advance.......
> Still learning......

Try:

syms Ri real

Subject: Real/Imaginary Part complex Numbers

From: Steven Lord

Date: 10 Feb, 2009 16:55:08

Message: 3 of 3


"matt reister" <mattreister@hotmail.com> wrote in message
news:gmothp$2gr$1@fred.mathworks.com...
>I am trying to take the real and imaginary part of a number. I can easily
>see what they are by inspection but i am trying to get matlab to tell me
>and its giving me crazy results.
>
> Here is my code
> L = 8.5*10^-6;
> C = 1200*10^-12;
> Rs = 330;
> R0 = 50;
> syms Ri
> W = 1/sqrt(L*C);
>
>
> Zl_Denom = 1 - W^2*L*C + i*(W*Ri*L)
> real_Zl_Denom = real(Zl_Denom)
>
> Here is the output i receive:
>
> Zl_Denom =
>
> 1/9007199254740992+13336086976169431513353727219037/158456325028528675187087900672*i*Ri
>
>
>
> real_Zl_Denom =
>
> 1/9007199254740992+13336086976169431513353727219037/316912650057057350374175801344*i*Ri-13336086976169431513353727219037/316912650057057350374175801344*i*conj(Ri)
>
> Is the reason its not returning the real part how i want it i.e. the value
> of 1 - W^2*L*C is because i have Ri defined as syms?

The reason real_Zl_Denom doesn't contain W, L, or C is because those
variables had numeric values when you computed Zl_Denom, and so those
numeric values were used in that computation. If you'd defined them as
symbolic variables using SYM or SYMS and computed Zl_Denom using those
symbolic variables, the expression real_Zl_Denom would likely contain one or
more of those variables.

If you're wondering about that conj(Ri), well, the symbolic engine didn't
know whether Ri could be complex or not. To tell the engine that it's
purely real, do what Joerg suggested and declare it as real.

syms Ri real

Then recompute Zl_Denom and real_Zl_Denom.

--
Steve Lord
slord@mathworks.com

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