How to separate real and imaginary components from a given expression in Matlab?
29 次查看(过去 30 天)
显示 更早的评论
Hello everyone I have a expression and I need to separate the real and imaginary components of the expression. I have written a simple code using symbolic math toolbox. The code is:
clc
syms X1 X2 XC RL
Zin=((X1*XC)-1i*(X2*RL))/(RL+1i*(X1*X2*XC));
A=real(Zin)
B=imag(Zin)
Can anyone please point out whats wrong with it or maybe another way to do this right.
Thank You.
0 个评论
采纳的回答
Steven Lord
2023-1-23
syms X1 X2 XC RL
Zin=((X1*XC)-1i*(X2*RL))/(RL+1i*(X1*X2*XC));
A=real(Zin)
B=imag(Zin)
What leads you to believe something is wrong? For general X1, X2, XC, and RL (which could be complex) that's the correct result. If you were to assume that they were real you get something a bit different.
syms X1 X2 XC RL real
A = real(Zin)
B = imag(Zin)
5 个评论
Walter Roberson
2023-1-23
We are not told that X1 X2 XC RL are real valued.
Suppose we had the expression 1i * X1 * X2 and we do not know that X1 and X2 are real. If we take real(1i * X1 * X2) is it correct that would be the same as X1*X2 ? Obviously not: real(1i * 3 * 5) = real(15i) = 0, which is not the same as real(3*5) = real(15) = 15. Should we guess then that real(1i * X1 * X2) = real(conj(X1 * X2)) ?
format long g
A = (3+4i) * (5+6i)
real(1i * A)
conj(A)
real(conj(A))
real(conj(3+4i) * conj(5+6i))
imag(3+4i) * imag(5+6i)
No. However it is correct that real(1i*A) == imag(A). Whether you write imag(A) or real(1i*A) is a matter of taste.
Steven Lord
2023-1-23
What's the real part of x+1i*y? If you said x you'd be incorrect in the general case, as shown by this example that substitutes numbers for x and y:
x = 1+2i;
y = 3+4i;
z = x + 1i*y
RE = real(z)
IM = imag(z)
RE == x % false
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!