Where is the wrong in this code??
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Aisha Mohamed
 il 31 Ago 2022
  
    
    
    
    
    Commentato: Aisha Mohamed
 il 1 Set 2022
            Because I trust the answers of all the Matlab experts in this group, and I thank all of them. The genius expert Torsten saw that there is some mistake in my code that used to plot cos(phase(f_b(1/z)), I used his notes but still there are some missing points in this work. I think this is because I did not write my question in the correct way. 
So I ask again where is the wrong in this code??
 I have two functions f_k(z) and f_b(1/z)  where,
 1-f_k(z) = (0.1000 + 0.3000i) + (0.4243 + 0.0017i)z + (0.9000- 0.0010i)z^2
we define p from f_k(z)as,
  p=[ ( 0.9000 - 0.0010i)  (0.4243 + 0.0017i) (0.1000 + 0.3000i) ];
2-f_b(1/z) = (0.1000 - 0.3000i)z^-1 + (0.2121 - 0.0008i)z^-2 + (0.9000 +0.0010i)z^-3 
we define p1 from f_b(1/z)as,
 p1=[ ( 0.9000 + 0.0010i)  (0.2121 - 0.0008i) (0.1000 - 0.3000i)  (0)]; 
   The function f_b(1/z) is not defined at z = 0 which means the graph of this function must be undefined at z = 0
      But when I use the code %f_of_1_over_z_result = polyval(p1, z); I found the graph for | f_b(1/z) | and | f_k (z) | are same
     and | f_b(1/z) | defined at z = 0 (which must not happen in  the myfunction |f_b(1/z)| because it is not defined at z = 0) , as you can see from the following figure:

But,  
%   Where as when I use the code %  f_of_1_over_z_result = polyval(p1,1./z);
%   the function |f_b(1/z)|does not define at z=0 (that what must happen in my case) as you can see in the following figure,

I used this code,
  p=[ ( 0.9000 - 0.0010i)  (0.4243 + 0.0017i) (0.1000 + 0.3000i) ];
 p1=[ ( 0.9000 + 0.0010i)  (0.2121 - 0.0008i) (0.1000 - 0.3000i)  (0)]; 
re_z = -6.005:.01:6.005;
im_z= -6.005:.01:6.005;
[re_z,im_z] = meshgrid(re_z,im_z);
z = re_z + 1i*im_z;
f_of_z_result = polyval(p,z); 
% %                                        
   f_of_1_over_z_result = polyval(p1,1./z);  % I used this code in the first figure
%   f_of_1_over_z_result = polyval(p1,z);   % I used this code in the second figure
figure();
subplot(2,2,1)
surf(re_z,im_z,abs(f_of_z_result),'EdgeColor','none')
colorbar
title('|f_k(z)|')
 xlabel('Z_R')  
ylabel('Z_I')
  zlim([0 15])   %adjust this value as needed 
  caxis([-6 6])  %adjust this value as needed
% grid on
subplot(2,2,2)
      surf(re_z,im_z,cos(angle(f_of_z_result)),'EdgeColor','none')
colorbar
 title('cos(phase of f_k(z))')
 xlabel('Z_R')  
ylabel('Z_I')
zlim([-5 5])   %adjust this value as needed
caxis([-1 1])    %adjust this value as needed 
subplot(2,2,3)
surf(re_z,im_z,abs(f_of_1_over_z_result),'EdgeColor','none')
colorbar
title('|f_b(1/z)|')
 xlabel('Z_R')  
ylabel('Z_I')  
 zlim([0 15])   %adjust this value as needed 
caxis([-0.15 0.15])
subplot(2,2,4)
  surf(re_z,im_z, cos(angle(f_of_1_over_z_result)),'EdgeColor','none')
colorbar
title(('cos(phase of f_b(1/z))'))
xlabel('Z_R')  
ylabel('Z_I')
 caxis([-1 1])    %adjust this value as needed 
 zlim([-1 1])   %adjust this value as needed    
grid on
Where is the wrong in this code??
0 Commenti
Risposta accettata
  Torsten
      
      
 il 31 Ago 2022
        
      Modificato: Torsten
      
      
 il 1 Set 2022
  
      f_b(1/z) = (0.1000 - 0.3000i)z^-1 + (0.2121 - 0.0008i)z^-2 + (0.9000 +0.0010i)z^-3
I wrote it several times already, but this function is the same as
f(w) = (0.1000 - 0.3000i)w + (0.2121 - 0.0008i)w^2 + (0.9000 +0.0010i)w^3
except for 1/z=w=0.
But if we define f_b(0) = 0, we remove this singularity and the two functions are identical all over the complex plane.
This can be seen in the first 4 graphics where we get a value of 0 for abs(f_b(1/z)) at 1/z=0.
So summarizing: There is nothing wrong in your code, but you must decide whether you want to define
f_b(1/z) = (0.1000 - 0.3000i)z^-1 + (0.2121 - 0.0008i)z^-2 + (0.9000 +0.0010i)z^-3
or 
f_b(z) = (0.1000 - 0.3000i)z^-1 + (0.2121 - 0.0008i)z^-2 + (0.9000 +0.0010i)z^-3
The first definition gives the 2 pictures in the first gallery, the second definition gives the 2 pictures in the second gallery.
3 Commenti
  Torsten
      
      
 il 1 Set 2022
				
      Modificato: Torsten
      
      
 il 1 Set 2022
  
			In order not to confuse people, the usual way to ask your question would have been
Given 
f_b(z) = (0.1000 - 0.3000i)z + (0.2121 - 0.0008i)z^2 + (0.9000 +0.0010i)z^3
and setting
g(z) = f_b(1/z)
how to plot abs(g(z)) and cos(phase(g(z))) ?
?
p1=[ ( 0.9000 + 0.0010i)  (0.2121 - 0.0008i) (0.1000 - 0.3000i)  (0)]; 
re_z = -6.005:.01:6.005;
im_z= -6.005:.01:6.005;
[re_z,im_z] = meshgrid(re_z,im_z);
z = re_z + 1i*im_z;
f_of_1_over_z_result = polyval(p1,1./z);  % I used this code in the first figure
figure
subplot(2,2,1)
surf(re_z,im_z,abs(f_of_1_over_z_result),'EdgeColor','none')
colorbar
title('|f_b(1/z)|')
xlabel('Z_R')  
ylabel('Z_I')  
zlim([0 15])   %adjust this value as needed 
caxis([-0.15 0.15])
subplot(2,2,2)
surf(re_z,im_z, cos(angle(f_of_1_over_z_result)),'EdgeColor','none')
colorbar
title(('cos(phase of f_b(1/z))'))
xlabel('Z_R')  
ylabel('Z_I')
caxis([-1 1])    %adjust this value as needed 
zlim([-1 1])   %adjust this value as needed    
grid on
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Subplots in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


