Problem with the product of complex numbers

Hello,
I calculated the equivalent impedance of an RLC circuit, and I would like this one to be completely resistive (complex part equals to 0). So I declared my variables as 'syms' and I used the function 'solve' to obtain the equivalent impedance litterally like:
% syms R X Y Z
% Zeq=solve('(R+i*X)*(-i*Y)/(R+i*X-i*Y)=Z',Z)
The problem is that Matlab gives me a solution like this:
%Zeq =
% -(Y*(R + X*i)*i)/(R + X*i - Y*i)
But I would like something like: Zeq = A + i*B.
Could anyone help?
Thanks

 Accepted Answer

Probably simplify(Zeq) will do that.

2 Comments

Thanks it's working! But now I've got another problem... When I multiply tne numerator of my fraction by the complex conjugate of the denominator, Matlab gives me this:
%sol = -Y*(R + X*i)*(X - Y + R*i)
instead of A + i*B. And this time 'simplify', or 'factor' don't work.
expandsol = expand(sol);
A = real(expandsol);
B = imag(expandsol);

Sign in to comment.

More Answers (1)

You cannot do that unless you add the assumption that the variables are real-valued
syms R X Y Z real
Zeq = simplify(solve((R+i*X)*(-i*Y)/(R+i*X-i*Y)-(Z),Z));
A = simplify(real(Zeq));
B = simplify(imag(Zeq));
A + B*i

8 Comments

Thanks. I have another question.
Now I would like 2 conditions: A=50 et B=0 in order to have a 2 equations on X. The expression of A being:
%A = (R*Y^2)/(R^2 + X^2 - 2*X*Y + Y^2)
When I use the function 'solve' written like this:
% S1=solve('(R*Y^2)/(R^2 + X^2 - 2*X*Y + Y^2)=50',X)
the code works, but when I write it like this:
% S1=solve('(A=50',X)
it doesn't...
Do you know why?
Because the aim is to calculate everything automatically, so if I have to copy/paste my result the program is useless...
Thanks
S1 = solve(A==50,X)
You need two equal signs ==, one equal sign = assigns a value to the variable on the left, which is not what you want to do here.
With this syntax, it tells me that X equals to 5, which is not possible because I didn't give any values to X and Y...
Anayway, I did the calculations on paper and the result should be:
% X = Y*(50-R)/50
That is curious. I can confirm neither of this:
syms R X Y real
A = (R*Y^2)/(R^2 + X^2 - 2*X*Y + Y^2)
solve(A==50,X)
simplify(ans)
yields
ans =
Y + (-2*R*(- Y^2 + 50*R))^(1/2)/10
Y - (-2*R*(- Y^2 + 50*R))^(1/2)/10
You might have assigned X or Y somewhere earlier in your session, if you want to make sure that they are "pristine" when you declare them as symbolic variables, do this
clear X Y R
syms X Y R real
It works when I do:
S10=solve(A-50,X)
S10=solve(A-50,X)
and
S10=solve(A==50,X)
should do the exact same thing, I can't think of one reason why one should work when the other doesn't.
What version of the Symbolic Toolbox are you using (command ver symbolic) ?
Before R2011b, "==" was processed as a logical relationship to be evaluated and the result of the logical evaluation to be passed into solve(). But those versions also did not know how to compare a symbol (with any content) against a number, so the expression would generate an error... unless, of course, A was a number instead of a symbol.
I see, I didn't know that -- so A-50 is the more robust syntax...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!