Matlab not running? No errors
1 次查看(过去 30 天)
显示 更早的评论
sig = 1; % Source strength % GRID: x = -150:.02:150; y = 0:.02:100; for m = 1:length(x) for n = 1:length(y) xx(m,n) = x(m); yy(m,n) = y(n); % Velocity potential function: phi_Source(m,n) = (sig/4/pi) * log(x(m)^2+(y(n)+.01)^2); % Stream function: psi_Source(m,n) = (sig/2/pi) * atan2(y(n),x(m)); end end % Plots % Source at origin of coordinat systex: contour(xx,yy,psi_Source,(-0.5:.5:5),'k') hold on contour(xx,yy,phi_Source,10,'r') legend('streamlines' ,'potential') title(' Source at origin') axis image hold off
1 个评论
Eric
2017-11-6
Here is the code properly formatted (you're welcome, Ricardeo):
sig = 1;
% Source strength
% GRID:
x = -150:.02:150;
y = 0:.02:100;
for m = 1:length(x)
for n = 1:length(y)
xx(m,n) = x(m);
yy(m,n) = y(n);
% Velocity potential function:
phi_Source(m,n) = (sig/4/pi) * log(x(m)^2+(y(n)+.01)^2);
% Stream function:
psi_Source(m,n) = (sig/2/pi) * atan2(y(n),x(m));
end
end
% Plots
% Source at origin of coordinate system:
contour(xx,yy,psi_Source,(-0.5:.5:5),'k')
hold on
contour(xx,yy,phi_Source,10,'r')
legend('streamlines' ,'potential')
title(' Source at origin')
axis image
hold off
ProTip: Check out meshgrid to transform it into:
[yy xx] = meshgrid(y,x);
phi_Source = (sig/4/pi) .* log(xx.^2+(yy+0.01).^2);
psi_Source = (sig/2/pi) .* atan2(yy,xx);
and avoid for loops.
回答(2 个)
Eric
2017-11-6
Be patient, it just takes a long time to display the plots. For me it took about 2 seconds for the contour functions to return and about 86 seconds for the figure to display. You may want to look into alternative ways to plot, or ways to reduce the number of elements plotted, if you desire speed.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!