MATLAB: Can anyone spot the mistake? I am trying to create a code that answers the question. A graph comes up, but nothing is in, so basically an empty graph with only the axis numbered (no plots). Can someone tell me why nothing is showing up

mechanical engineering

The question i am asked is:
Generate a 21 X 21 mesh on a xy coordinate system. Mesh x & y are bounded in a square -1≤x≤1 & -1≤y≤1. At each grid point, u(x,y)=1/x, v(x,y)=1/y. Plot (u,v) vector at each grid (x,y) in the given region. [Hint: dx=dy=0.1 ]
My code is:
clc;
dx=0.1;
[x,y] = meshgrid(-1:dx:1, -1:dx:1); % creating meshgrid
u=1./x;
v=1./y;
quiver(x,y,u,v);
axis equal

Best Answer

I think the problem is that your u and v variables have Inf values, which (I'm guessing) throw off the automatic scaling of the arrow lengths.
The following code produces output:
dx=0.1;
[x,y] = meshgrid(-1.05:dx:1, -1.05:dx:1); % creating meshgrid
u=1./x;
v=1./y;
quiver(x,y,u,v);
axis equal