Christopher
Christopher

Reputation: 137

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?:

Upvotes: 0

Views: 301

Answers (1)

Fija
Fija

Reputation: 195

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

Upvotes: 2

Related Questions