Matlab not running? No errors

3 次查看(过去 30 天)
Ricardeo Xavier
Ricardeo Xavier 2017-11-6
评论: Eric 2017-11-6
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
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 个)

Image Analyst
Image Analyst 2017-11-6
It runs for me. Takes like 25 minutes though. What is your question?

Eric
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.

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by