basic123
basic123

Reputation: 23

How to get imaginary and real part of complex expression symbolically in Matlab?

I am trying to get the imaginary and real part of following complex expression.

syms a b
F = imag((cos(a)-j*sin(a))/(1+j*a*b-cos(a)+j*sin(a)))
simplify(F)

The output is same with or without simplify. Is there any way to express this expression in standard complex number format (x+jy)?

Upvotes: 2

Views: 709

Answers (1)

jodag
jodag

Reputation: 22204

Nothing is assumed about a and b by default, meaning that they may be complex. Because of this, MATLAB can't determine a closed form expression for the imaginary component. If you know that a and b are real numbers then you can impose this assumption as follows.

syms a b real
F = imag((cos(a)-j*sin(a))/(1+j*a*b-cos(a)+j*sin(a)))

Alternatively, you can change the assumptions for a symbolic object after declaration using the assume function.

Upvotes: 2

Related Questions