Simplifying a complex function in order to separate real and imaginary part?

39 次查看(过去 30 天)
How to Simplify a complex function in order to separate its real and imaginary parts?
For instance, I have the symbolic function 's' as follows and I want to know what is its real part....
syms r theta real
s=(exp(-theta*1i)*((1 - r*exp(theta*1i))^(3/2) - 1))/(3*r);
% real(s)=? imag(s)=?
s1=real(s); % Does not yield the answer. So I try the following command
S=rewrite(s,'sincos');
S1=simplify(collect(real(S))); % Again does not yield the answer....
%s1=real((exp(-theta*1i)*((1 - r*exp(theta*1i))^(3/2) - 1))/r)/3
%S1=real((((1 - r*(cos(theta) + sin(theta)*1i))^(3/2) - 1)*(cos(theta) - sin(theta)*1i))/r)/3
  2 个评论
zah ra
zah ra 2020-9-12
I want some symbolic function in 'r' and 'theta' variables as the real part of 's' (independent from the basic imaginary unit 'i')

请先登录,再进行评论。

回答(2 个)

Ameer Hamza
Ameer Hamza 2020-9-12
编辑:Ameer Hamza 2020-9-12
Due to the term (1 - r*exp(theta*1i))^(3/2) in your expression, it might not be possible to write an explicit expression (maybe an infinite series is possible) for the real and complex parts. However, if you just care about the numeric output, the real(s) does give real values
syms r theta
s = (exp(-theta*1i)*((1 - r*exp(theta*1i))^(3/2) - 1))/(3*r);
S = real(s);
S = matlabFunction(S, 'Vars', {'r', 'theta'});
v = S(2, 0:0.1:10); % some values
tf = all(v==real(v)); % test if all are real
tf
Result
>> test
tf =
logical
1
  4 个评论

请先登录,再进行评论。


David Goodmanson
David Goodmanson 2020-9-13
编辑:David Goodmanson 2020-9-13
Hi zah ra,
An explicit form for real and imaginary parts of
(1 - r*exp(theta*1i))^(3/2)
is possible, although not particularly convenient. You are using the 3/2 power, but the code below works for any (real) power n. Also the code is for r<1, but with a bit more work it can be modified for the case r>1.
r = .6;
th = 0:.001:2*pi;
n = 1.536;
% exact expressions, want to reproduce these
re1 = real((1-r*exp(i*th)).^n);
im1 = imag((1-r*exp(i*th)).^n);
% obtain equivalent expressions in terms of real functions
a = sqrt(r^2+1-2*r*cos(th)); % third side of the 1(one),r,a triangle
phi = -asin((r./a).*sin(th)); % angle between 'a' and the x axis
re2 = a.^n.*cos(n*phi);
im2 = a.^n.*sin(n*phi);
% compare with re1,im1.
% re2 and im2 are offset for visual purposes
plot(th,[re1;im1;re2+.05;im2+.05])
After finding the expressions for real and imag, you can go back to symbolic multiplication to obtain the real and imaginary parts of s. But as is usually the case, It's a lot of trouble to recreate complex algebra in terms of real quantities, and the resulting jumble of code is not particularly revealing. Maybe there is good reason to do that in your case. But most of the time, numerical results are ultimately what is wanted. Then it is a lot more convenient, compact and error-free to allow complex algebra to do its thing and use real(s) and imag(s) afterward.

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by