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

68 visualizaciones (últimos 30 días)
zah ra
zah ra el 12 de Sept. de 2020
Comentada: zah ra el 13 de Sept. de 2020
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 comentarios
KSSV
KSSV el 12 de Sept. de 2020
Why do you think real(s) is not givng you the realpart of s?
zah ra
zah ra el 12 de Sept. de 2020
I want some symbolic function in 'r' and 'theta' variables as the real part of 's' (independent from the basic imaginary unit 'i')

Iniciar sesión para comentar.

Respuestas (2)

Ameer Hamza
Ameer Hamza el 12 de Sept. de 2020
Editada: Ameer Hamza el 12 de Sept. de 2020
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 comentarios

Iniciar sesión para comentar.


David Goodmanson
David Goodmanson el 13 de Sept. de 2020
Editada: David Goodmanson el 13 de Sept. de 2020
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.

Categorías

Más información sobre Numbers and Precision en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by