How to plot the function f(1/z) in matlab where z is any complex number

36 views (last 30 days)
I work in both function f(z) and f(1/z) and the coefficiens of both change with time t. and z is complex number.
For example time = 0:0.01:2*pi at every time t I have to find f(z) and f(1/z) and plot them in order to find the graphs of these functions.
This is what I did:
I used (for loop )to calculate the coefficient of f(z) at every time ( time = 0:0.01:2*pi ). Then at each time t and its corresponding coefficients I plot p=f(z) and polyval(p,1./z), but I have to choose spicific value of z to plot polyval(p,1./z) .
The problem is how to check these graphs are correct? and how can me plot both function in whole complex plane(for any arbitrary values of z)
Thank you very much

Accepted Answer

Voss
Voss on 23 Mar 2022
You say p=f(z), so that p is the value of the function f at some particular value(s) of z.
Then you do polyval(p,1/z), which doesn't seem right to me. polyval() would use the coefficients of f, which is not the same as the value of f at z.
You mention you already calculate the coefficients of f (for each time), so that's what should be used in polyval(). Maybe it is just unclear notation in the question.
In any case, here are two ways to evaluate f(z) and f(1/z). The first way defines an anonymous function f, and the second way uses polyval() with the coefficients of the polynomial f. (The actual plotting is done the same way in either case.)
1) anonymous function:
% define the function f(z):
% f(z) = z^2-2*z+1
f = @(z)z.^2-2*z+1; % anonymous function
% define the region on the complex plane to plot over:
% -1 <= Re{z} <= 1
% -1 <= Im{z} <= 1
re_z = -1:0.01:1;
im_z = -1:0.01:1;
% use meshgrid() to get matrices of (re_z,im_z) grid points
% that f(z) and f(1/z) will be evaluated at:
[re_z,im_z] = meshgrid(re_z,im_z);
% z values corresponding to those (re_z,im_z) points:
z = re_z + 1i*im_z;
% evaluate f at those z's:
f_of_z_result = f(z);
% evaluate f at 1/(those z's):
f_of_1_over_z_result = f(1./z);
% plot the magnitude and phase of f(z) and f(1/z):
figure();
subplot(2,2,1)
surf(re_z,im_z,abs(f_of_z_result),'EdgeColor','none')
title('|f(z)|')
subplot(2,2,2)
surf(re_z,im_z,angle(f_of_z_result),'EdgeColor','none')
title('phase of f(z)')
subplot(2,2,3)
surf(re_z,im_z,abs(f_of_1_over_z_result),'EdgeColor','none')
title('|f(1/z)|')
subplot(2,2,4)
surf(re_z,im_z,angle(f_of_1_over_z_result),'EdgeColor','none')
title('phase of f(1/z)')
2) coefficients and polyval():
% define the function f(z) in terms of its coefficients p:
% f(z) = z^2-2*z+1
p = [1 -2 1]; % polynomial coefficients p instead of anonymous function f
% evaluate f over all z in ([-1,1],[-1,1]):
f_of_z_result = polyval(p,z);
% evaluate f at 1/z:
f_of_1_over_z_result = polyval(p,1./z);
% plot the magnitude and phase of f(z) and f(1/z):
% (same as before)
figure();
subplot(2,2,1)
surf(re_z,im_z,abs(f_of_z_result),'EdgeColor','none')
title('|f(z)|')
subplot(2,2,2)
surf(re_z,im_z,angle(f_of_z_result),'EdgeColor','none')
title('phase of f(z)')
subplot(2,2,3)
surf(re_z,im_z,abs(f_of_1_over_z_result),'EdgeColor','none')
title('|f(1/z)|')
subplot(2,2,4)
surf(re_z,im_z,angle(f_of_1_over_z_result),'EdgeColor','none')
title('phase of f(1/z)')
  1 Comment
Torsten
Torsten on 25 Mar 2022
@Aisha Mohamed comment moved here:
Thank you very muchfor these worth information, I want to add some information that make this question more clear
1- I use p=[(0.9-0.124i) (0.4243 + 0.0017i) (0.10 + 0.3i)]; and as t change time = 0:0.01:2*pi (polynomial in z inthe second degree) f(z) = (0.10 + 0.3i) + (0.4243 + 0.0017i)z + (0.9-0.124i)z^2
the coefficients of p will cange with time by using this relation | f(t)> =exp(i t H)|f(0)>,for some H (given) and |f(0)> are the coefficients of p at t=o, and at every time I have new coefficients | f(t)> and plot the function p.
2- the function f(1/z) at every time must use the complex conjugate of the coeffecients of p (multiply in some constants)which also change with time t by the same way that coefficients of p do(in this case f(1/z) is the function of 1/z in the third degree) f(1/z) = (0.10 0.3i)z^-1 + (0.2121 0.0008i)z^−2 + (0.9 + 0.001i)z^−3.
How can I plot the two function in this case?
When I am trying to plot f(z) and f(1/z) I got paths in complex plane (not serface). and I am not sure that plots are correct.
I will appreciate any help

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!