MATLAB: 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))

sin sqrt

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

Best Answer

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.