2016-11-21 14 views
5

我最近嘗試在我的流體問題集中繪製一些教程問題的velocicty字段。我寫了下面Matlab代碼Matlab代碼不會繪製函數的一部分

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 

它分別給了我下面的 First Function

enter image description here

第一和第二功能。我無法弄清楚爲什麼它不會爲n繪製陰性...我試圖隔離一切,但最終還是無法完全調試它。

+0

有趣的是,該數據確實存在,但你不能看到它。 '顫抖(x1,x2,u1,u2,'o')'會顯示出來。 –

+0

@AnderBiguri是的,我剛剛嘗試過,它的工作原理,但我確實想要矢量形式。這太奇怪了。 – thephysicsguy

回答

6

問題是,對於負數n,矩陣u1u2在某些條目中包含無限值。 quiver自動縮放值,因此所有內容都被壓縮爲零,因此不會顯示在圖形中。

一種解決方案是通過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 

這給

enter image description here

enter image description here

+0

哦,當然,第一次迭代是找到1/0^n因此Inf值。不知道爲什麼我沒有看看u1和u2陣列。非常感謝! – thephysicsguy