Matlab code will not display part of the function

Recently, I tried to build some velocity fields for a training problem in my fluid problems problem. I wrote the following matlab code

clear; h_theta_multiple=0.01; h_theta=h_theta_multiple*2*pi; h_rho=0.1; [theta,rho] = meshgrid(0:h_theta:2*pi,0:h_rho:5); [x1,x2] = pol2cart(theta,rho); N=[1 2 3 -1 -2 -3]; figure for i=1:length(N) n=N(i); u1 = rho.^n .* cos(n.*theta); u2 = rho.^n .* sin(n.*theta); subplot(2,3,i); quiver(x1,x2,u1,u2); end figure for i=1:length(N) n=N(i); u1 = -rho.^n .* sin(n.*theta); u2 = rho.^n .* cos(n.*theta); subplot(2,3,i); quiver(x1,x2,u1,u2); end 

It gives me the following First function

enter image description here

for the first and second functions, respectively. I cannot understand why this does not mean that for n it is negative ... I tried to isolate everything, but I could not debug it at the end.

+5
source share
1 answer

The problem is that for negative n matrices u1 and u2 contain infinite values ​​in some elements. quiver automatically scales the values, so everything is compressed to zero and therefore not displayed on the chart.

The solution is to replace the infinite values ​​with NaN :

 clear; h_theta_multiple=0.01; h_theta=h_theta_multiple*2*pi; h_rho=0.1; [theta,rho] = meshgrid(0:h_theta:2*pi,0:h_rho:5); [x1,x2] = pol2cart(theta,rho); N=[1 2 3 -1 -2 -3]; figure for i=1:length(N) n=N(i); u1 = rho.^n .* cos(n.*theta); u2 = rho.^n .* sin(n.*theta); u1(isinf(u1)) = NaN; % replace infinite values by NaN u2(isinf(u2)) = NaN; subplot(2,3,i); quiver(x1,x2,u1,u2); end figure for i=1:length(N) n=N(i); u1 = -rho.^n .* sin(n.*theta); u2 = rho.^n .* cos(n.*theta); u1(isinf(u1)) = NaN; % replace infinite values by NaN u2(isinf(u2)) = NaN; subplot(2,3,i); quiver(x1,x2,u1,u2); end 

This gives

enter image description here

enter image description here

+6
source

Source: https://habr.com/ru/post/1260084/


All Articles