简体   繁体   中英

Plotting a 3D Function

Im trying to plot the following function: F(x,y)=Cos(x)*Sin(y) With the following features: Labeled all three axes, the x and y axes range from 0 to 2pi with 0.1 spacing, and the viewing angles are orthogonal to any x/y/z=0 plane.

I have the following code

t= 0:0.1:2*pi;
A=cos(t);
B=sin(t);
for i=1:numel(t)
C(:,i)=A(i).*B(:);
end
surf(C);
xlabel('x axis','fontsize',12)
ylabel('y axis','fontsize',12)
zlabel('z axis','fontsize',12)
title ('3D Plot')

That is almost what I need, for some reason the chart is plotting x and y from 0 to 80, and Im not sure why. I there another way I can try plotting this so that I can use different variables for the cosine and sine inputs?:

I think you wanna do

surf(t,t,C)

instead of only surf(C). Now it will range from 0 to 2pi. You need to define the x- and y-values if you want them to have specific values.

You might want to use this as well, to remove the unnecessary parts of the axises.

axis tight

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM