Create two vectors X and Y of values from (-pi) to pi with a spacing of pi/10. Define the vector Z as: Z = (sin(sqrt(​x^2+y^2)))​/(sqrt(x^2​+y^2))

8 次查看(过去 30 天)
Im trying to plot function. I have wrote x=[-pi:pi/10:pi] and y=[-pi:pi/10:pi]. Also Z = (sin(sqrt(x.^2+y.^2)))/(sqrt(x.^2+y.^2)). When I try to plot the function z somehow gets to be only one number such as -0.0227 and I get error 'Vectors must be the same lengths'. Please help me to get this problem right

采纳的回答

Roger Stafford
Roger Stafford 2014-3-18
You need to put a "dot" in your division operator:
Z = (sin(sqrt(x.^2+y.^2)))./(sqrt(x.^2+y.^2))
What you had there without the dot was matrix division which in this case produces a single scalar.
I am curious though as to what you are trying to do. Both the x and y vectors are identical. It looks as though you were attempting to accomplish something other than what you produced in the code. If so, please tell what that is.

更多回答(2 个)

Lisa
Lisa 2014-3-18
Im trying to plot in mesh and surf same problem above. Im writing plot3(x,z,y,z); subplot(2,2,1) mesh(x,z,y,z) title('Mesh Plot'),xlable('x-axis'),ylable('y-axis'),zlable('z-axis') I would have to make three different shading scheme as well, so if you could help me that would be awesome!

Marta Salas
Marta Salas 2014-3-18
编辑:Marta Salas 2014-3-18
[x,y] = meshgrid(-pi:pi/10:pi)
z = (sin(sqrt(x.^2+y.^2)))./(sqrt(x.^2+y.^2))
mesh(x,y,z)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by