3D plot and contour plot

Question 1)
The following is my function z. Please help me to generate a 3D plot and a contour plot.
function out=z(x,y,n)
p=(1+sin(5*x))-(1/sqrt(8*(sin(x))))
q=(1+sin(5*y))+(1/sqrt(8*(sin(y))))
if fix(n/2)==n/2
out=n*(p+q)
else
out=(n-1)*(p+q)+p
end
x is in the range of 0 to 6, increment 0.1
y also in the range of 0 to 6, increment 0.1
z is in the range of -0.005 to -2.000

Respuestas (1)

Walter Roberson
Walter Roberson el 10 de Oct. de 2012
Editada: Walter Roberson el 10 de Oct. de 2012

0 votos

0) 0.1 is called the "increment" there
1) see mesh() and contour()
2) length(m) will be 101, or size(m) will show 1 101
3) Yes.

4 comentarios

Walter Roberson
Walter Roberson el 10 de Oct. de 2012
Also, see surf()
The meshgrid() that you had previously was a good start.
Enfa White
Enfa White el 10 de Oct. de 2012
I tried with the following codes:
function out=z(~,~)
x = linspace(0,6,61); y = linspace(0,6,61);
p=(1+sin(5*x))-(1/sqrt(8*(sin(x)))); q=(1+sin(5*y))+(1/sqrt(8*(sin(y))));
out=(16*(p+q))/2+p;
[x,y] = meshgrid(0:0.1:6,0:0.1:6);
figure surfc(x,y,z); shading interp;
title('A function','FontSize',16) axis([0 6 0 6 -0.005 -2.000])
But I got the following errors, please advise:
??? Error using ==> mldivide Matrix dimensions must agree.
Error in ==> z at 6 p=(1+sin(5*x))-(1/sqrt(8*(sin(x))));
Walter Roberson
Walter Roberson el 10 de Oct. de 2012
Change the 1/ to 1./
Enfa White
Enfa White el 10 de Oct. de 2012
I already tried to change / to ./ at the following equations:
p=(1+sin(5*x))-(1./sqrt(8*(sin(x)))); q=(1+sin(5*x))+(1./sqrt(8*(sin(x))));
out=(16*(p+q))./2+p;
When I run it, the empty figure keep opening continuously until I terminate the Matlab program. By the way is there any command that I can enter at the command window to stop this problem? TQ.

Iniciar sesión para comentar.

Categorías

Más información sobre Contour Plots en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 10 de Oct. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by