why my code gives different result then the formula
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,I have triedto implent the formula shown bellow in matlab to create the plot shown bellow.
but when i implemented the formula using the code bellow i get a tottaly different plot then the theory as shown bellow.
Where did i go wrong?
Thanks.
[theta,phi] = meshgrid(-pi:0.2:0.5*pi,-pi:0.2:pi);
f=10;
lambda=300/f;
k=(2*pi)/lambda;
N=10;
M=10;
dx=0.5*lambda;
dy=0.5*lambda;
ksi_x=k*dx.*sin(theta).*cos(phi);
ksi_y=k*dy.*sin(theta).*sin(phi);
AF=((1/M)*((sin(0.5*M*ksi_x))./(sin(0.5*ksi_x)))).*((1/N)*((sin(0.5*N*ksi_y))./(sin(0.5*ksi_y))));
surf(phi,theta,AF)
colorbar
%polarplot(theta,AF)
%delta=-k*d*cos(theta_0);
%AF=(1/N)*((sin(0.5*N.*ksi))./(sin(0.5*ksi)));
댓글 수: 0
답변 (1개)
Star Strider
2021년 12월 17일
Nothing wrong, just that to get it to appear in polar coordinates, the surface data need to be processed first with the pol2cart function, then plotted. It looks as though it still needs a bit of effort to get it to look like the first two images, however this should help get the correct plot.
It will ikely be necessary to experiment with the order of the first two arguments to pol2cart since I have no idea what the correct order is in this instance. Another option could be sph2cart and since I am not certain wha the objective is here, consider it as well.
[theta,phi] = meshgrid(-pi:0.2:0.5*pi,-pi:0.2:pi);
f=10;
lambda=300/f;
k=(2*pi)/lambda;
N=10;
M=10;
dx=0.5*lambda;
dy=0.5*lambda;
ksi_x=k*dx.*sin(theta).*cos(phi);
ksi_y=k*dy.*sin(theta).*sin(phi);
AF=((1/M)*((sin(0.5*M*ksi_x))./(sin(0.5*ksi_x)))).*((1/N)*((sin(0.5*N*ksi_y))./(sin(0.5*ksi_y))));
[X,Y,Z] = pol2cart(phi, theta, AF); % Polar Coordinate Transformation
figure
surf(phi,theta,AF)
colorbar
figure
surf(X, Y, Z) % Polar Coordinate Plot
colorbar
%polarplot(theta,AF)
%delta=-k*d*cos(theta_0);
%AF=(1/N)*((sin(0.5*N.*ksi))./(sin(0.5*ksi)));
.
댓글 수: 2
Star Strider
2021년 12월 17일
Thank you!
The variables were polar, however they were plotted as though they were Cartesian, because the surf function interprets them that way. In order for them to correctly appear polar, they need to be transformed from polar to Cartesian, so that MATLAB’s Cartesian coordinate system will plot them correctly.
Also, limting the ‘x’ and ‘y’ axes in the polar plot, and increasing the resolution (by decreasing the step size in the original vectors) will produce a plot that more closely resembles the plots in the second posted image.—
[theta,phi] = meshgrid(-pi:0.01:0.5*pi,-pi:0.01:pi);
f=10;
lambda=300/f;
k=(2*pi)/lambda;
N=10;
M=10;
dx=0.5*lambda;
dy=0.5*lambda;
ksi_x=k*dx.*sin(theta).*cos(phi);
ksi_y=k*dy.*sin(theta).*sin(phi);
AF=((1/M)*((sin(0.5*M*ksi_x))./(sin(0.5*ksi_x)))).*((1/N)*((sin(0.5*N*ksi_y))./(sin(0.5*ksi_y))));
[X,Y,Z] = pol2cart(phi, theta, AF); % Polar Coordinate Transformation
figure
surf(phi,theta,AF)
colormap(turbo) % New In R2021a
colorbar
shading('interp')
figure
surf(X, Y, Z) % Polar Coordinate Plot
colormap(turbo) % New In R2021a
colorbar
shading('interp')
xlim([-1 1]*0.75) % Axis Limits
ylim([-1 1]*0.75) % Axis Limits
Experiment to get the desired result.
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Purple에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!