Matlab not running? No errors

1 Ansicht (letzte 30 Tage)
Ricardeo Xavier
Ricardeo Xavier am 6 Nov. 2017
Kommentiert: Eric am 6 Nov. 2017
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 Kommentar
Eric
Eric am 6 Nov. 2017
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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

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

Eric
Eric am 6 Nov. 2017
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.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by