Matlab not running? No errors

3 views (last 30 days)
Ricardeo Xavier
Ricardeo Xavier on 6 Nov 2017
Commented: Eric on 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 Comment
Eric
Eric on 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.

Sign in to comment.

Answers (2)

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

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

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!