|
"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
|