How do I use "real()" on symbolic expressions to give me an acceptable result?

1 view (last 30 days)
I am trying to get matlab to give me the real (or imaginary) part of a complicated rational expression with several complex variables. However, it won't return an answer when I use the "real()" command. How can I get the actual expression? I tried making sure the variables are assumed to be real and positive, but it doesn't seem to help. I have pasted a sample of my code below.
syms Rp Lp Cp Rm Rox Cox x Z0 real;
syms Rp Lp Cp Rm Rox Cox x Z0 positive;
Z_A = 1i*x*Lp + Rp;
Z_B = 1/(1i*x*Cp);
Z_C = Rm + Rox/(1i*x*Cox*Rox + 1);
Z11 = Z_A + Z_B;
Z21 = Z_B;
Z12 = Z_B;
Z22 = Z_B + Z_C;
S11_denominator = (Z11+Z0)*(Z22+Z0)-Z12*Z21;
S11_numerator = ((Z11-Z0)*(Z22+Z0) - Z12*Z21);
S11 = S11_numerator/S11_denominator;
And the output is:
ans =
real(((Rp - Z0 + Lp*x*i - i/(Cp*x))*(Rm + Z0 - i/(Cp*x) + Rox/(Cox*Rox*x*i + 1)) + 1/(Cp^2*x^2))/((Rp + Z0 + Lp*x*i - i/(Cp*x))*(Rm + Z0 - i/(Cp*x) + Rox/(Cox*Rox*x*i + 1)) + 1/(Cp^2*x^2)))

Answers (1)

Star Strider
Star Strider on 13 Jun 2014
Add after your S11 assignment:
S11 = simplify(collect(S11))
S11R = real(S11)
S11I = imag(S11)
It seems to work for me, and contains no functions of ‘i’ in either.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!