How to separate real and imaginary components from a given expression in Matlab?
조회 수: 28 (최근 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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!