Data must be a single matrix Y or a list of pairs X,Y

조회 수: 3 (최근 30일)
Khaled
Khaled 2025년 3월 27일
편집: VBBV 2025년 4월 1일
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
=====================================

답변 (2개)

Mathieu NOE
Mathieu NOE 2025년 3월 27일
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
Khaled
Khaled 2025년 4월 1일

Dear Sir, Unfortunately, it is still not solved in 2D. !

Mathieu NOE
Mathieu NOE 2025년 4월 1일
what is the name of this curve ? can you share the publication or book page you are working on ?

댓글을 달려면 로그인하십시오.


VBBV
VBBV 2025년 3월 27일
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
Khaled
Khaled 2025년 3월 28일
Yes sir,
I have spent a lot of time working on it using implicit! But all the tries fail!
VBBV
VBBV 2025년 3월 28일
편집: VBBV 2025년 4월 1일
@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');

댓글을 달려면 로그인하십시오.

태그

제품


릴리스

R2011a

Community Treasure Hunt

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

Start Hunting!

Translated by