Matlab not running? No errors

조회 수: 2 (최근 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에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by