Data must be a single matrix Y or a list of pairs X,Y
    4 views (last 30 days)
  
       Show older comments
    
My aim is to plot 2d the function ph (xx,yy) in the plane (xx,yy). 
x-axis is xx,  y-axis is yy, and the function ph(xx,yy) 
=====================================================
q=1.0;
v=(1.0-sqrt(1.0+4.0*q))/(2.0*q);
p=4*atan(1.0);
for j=0:100
    a=0.0+j.*p/100;
    fori=0:100
    b=0.0+i.*p/100;
    x=cos(a);
    y=sin(b);
    z=x.*x+y.*y;
    if z<1.0
        xx=x;
        yy=y;
        zz=z;
        D=1.0+q.*(v.*v)*(zz.*zz);
        N=1.0-v.*zz-q.*(v.*v)*(zz.*zz);
        ph=D/N;
        hold on
        plot(xx,yy,ph)
    end 
end 
end 
 =====================================
Answers (2)
  Mathieu NOE
      
 on 27 Mar 2025
        hello 
maybe this ? 
I prefer to avoid using i and j as loop indexes as those letters usually are reserved as the iamginary unit in matlab (so I took cj and ci )
index start at 1 and not 0 in matlab 
then there was a uncovered condition in this loop : if z<1.0    you need to define what should be ph if this condition is not met
clc
clearvars
q=1.0;
v=(1.0-sqrt(1.0+4.0*q))/(2.0*q);
 p=4*atan(1.0);
for cj=1:100
    a=0.0+cj.*p/100;
    x=cos(a);
    xs(cj) = x; % store current x value in array xs
    for ci=1:100
       b=0.0+ci.*p/100;
        y=sin(b);
        ys(ci) = y;% store current y value in array ys
        z=x.*x+y.*y;
         if z<1.0
            xx=x;
            yy=y;
            zz=z;
           D=1.0+q.*(v.*v)*(zz.*zz);
           N=1.0-v.*zz-q.*(v.*v)*(zz.*zz);
           ph(cj,ci)=D/N;
         else  % /!\ was missing 
             ph(cj,ci)= z ; % <== put the correct value here
         end
     end 
end
 surf(xs,ys,ph)
9 Comments
  Mathieu NOE
      
 on 1 Apr 2025
				what is the name of this curve ? can you share the publication or book page you are working on ? 
  VBBV
      
      
 on 27 Mar 2025
        hold on
q=1.0;
v=(1.0-sqrt(1.0+4.0*q))/(2.0*q);
 p=4*atan(1.0);
for j=0:100
    a=0.0+j.*p/100;
        for i=0:100
       b=0.0+i.*p/100;
 x=cos(a);
y=sin(b);
 z=x.*x+y.*y;
 if z<1.0
    xx=x;
    yy=y;
    zz=z;
   D=1.0+q.*(v.*v)*(zz.*zz);
 N=1.0-v.*zz-q.*(v.*v)*(zz.*zz);
 ph=D/N;
   % hold on
 plot3(xx,yy,ph,'bo')
     end 
  end 
end
%surf(xx,yy,ph)
     %v=(1.0-sqrt(1.0+4.0*q))/(2.0*q); p=4*atan(1.0);for j=0:100  a=0.0+j.*p/100;      fori=0:100     b=0.0+i.*p/100; x=cos(a);y=sin(b); z=x.*x+y.*y; if z<1.0  xx=x;  yy=y;  zz=z; D=1.0+q.*(v.*v)*(zz.*zz); N=1.0-v.*zz-q.*(v.*v)*(zz.*zz); ph=D/N;   hold on plot(xx,yy,ph)end    end   end 
5 Comments
  VBBV
      
      
 on 28 Mar 2025
				
      Edited: VBBV
      
      
 on 1 Apr 2025
  
			@Khaled the question is not clear with missing details. i can guess in this case, that x and y values need to checked in each loop itreation. 
hold on
q= 1; %linspace(0,1.0,5);
v=(1.0-sqrt(1.0+4.0*q))./(2.0*q);
k = 1;
 p=4*atan(1.0);
for j=0:200
    a=0.0+j.*p/180;  % check 
        for i=0:0.5:100
       b=0.0+i.*p/180;  % check
 x=cos(3*b);
 y=cos(b);
 z=x.*x+y.*y;
 if z<1.0
    xx(k)=x;
    yy(k)=y;
    zz=z;
   D=1.0+q.*(v.*v)*(zz.*zz);
 N=1.0-v.*zz-q.*(v.*v)*(zz.*zz);
 ph(k)=(D)./N;
   k = k+1;
     end 
  end 
end
plot(-xx(:),(ph(:)),'bo'); xlim([-0.25 0.25])
%q= 1; %linspace(0,1.0,5);v=(1.0-sqrt(1.0+4.0*q))./(2.0*q);k = 1; p=4*atan(1.0);for j=0:100  a=0.0+j.*p/180;  % check       for i=0:100     b=0.0+i.*p/180;  % check x=cos(a);y=sin(b); z=x.*x+y.*y; if z<1.0  xx(k)=x;  yy(k)=y;  zz=z; D=1.0+q.*(v.*v)*(zz.*zz); N=1.0-v.*zz-q.*(v.*v)*(zz.*zz); ph(k)=(D)./N; k = k+1;      end end endplot(xx(:),(ph(:)),'bo'); 
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






