Hello,
There are several approaches that you can try to eleminate the point inside the circle. Here, I can show you a solution
T=100;
m=10;
A=10;
B=10;
R=30;
th=0:pi/100:2*pi;
X=R*cos(th)+A;
Y=R*sin(th)+B;
x = zeros(1,m);
y = zeros(1,m);
DX=20;
for j=1:m
for i=1:T
xnext = x(i,j)+DX*randn();
ynext = y(i,j)+DX*randn();
cond = norm([xnext-A,ynext-B]);
while (cond < R)
xnext = x(i,j)+DX*randn();
ynext = y(i,j)+DX*randn();
cond = norm([xnext-A,ynext-B]);
end
x(i+1,j)=xnext;
y(i+1,j)=ynext;
end
end
plot(x(2:end,:),y(2:end,:),'k.');
hold on;
plot(X,Y,'r');
title (['Time = ', num2str(T),', Particles = ', num2str(m)]);
xlabel("space x");
ylabel("space y");
hold off;
Now, you will get rid of the previous error.
Best Answer