I have a problems to graph in 3D

when i run it tells me that "vectors must be the same length" and "error (line7) plot3(x,y,z)"
clc
clear all
x=-20:0.01:30;
y=-20:0.01:30;
%Ecuacion
z=sin(sqrt(x.^2+y.^2))/sqrt(x.^2+y.^2+0.2);
plot3(x,y,z)
[A,B]=meshgrid(-30:0.1:20);
Z=sin(sqrt((A.^2)+(B.^2)))/sqrt(A.^2+B.^2+0.2);
figure
mesh(A,B,Z)

Answers (1)

‘vectors must be the same length’
Yes, they must.
If you remember to use element-wise division:
z=sin(sqrt(x.^2+y.^2))./sqrt(x.^2+y.^2+0.2);
↑ ← HERE
they are, and the first figure plots correctly.
Remember to do that in the second one as well:
Z=sin(sqrt((A.^2)+(B.^2)))./sqrt(A.^2+B.^2+0.2);
↑
and that figure plots correctly as well.

2 Comments

My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

This question is closed.

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!