フィルターのクリア

Plotting results within a circle

1 回表示 (過去 30 日間)
Mike
Mike 2014 年 3 月 19 日
Hello,
I am writing a code to find points between zero and 1. I need to figure a way to plot this points on the domain which is a circle. Each time i try to do it, it seems to plot the points between zero and one, but goes farther down the line for the number of iterations that i am doing. Meaning the points are there, but they just advance down the graph. How would i go about plotting them all within a circle?
Here is my code
clear;
clc;
n = 50; %--Number of simulations--%
X = linspace(0,1,n);
s = zeros(n,n);
%--Plot of the circle--%
figure(1)
clf;
syms p
bc = sin (p);
bc2 = cos (p);
Range = [0 2*pi];
subplot(211);
h = ezplot(bc,bc2,[Range]);
hold on
for t=1:n
%--General Formula for Randomization over a range--%
a = -1;
b = 1;
MoveX = a + (b-a).*rand(1);
MoveY = a + (b-a).*rand(1);
if MoveY <=0
MoveY = 0;
% elseif MoveY >=0
% MoveY = 1;
end
%--Determining movment of each random variable--%
distance(t) = MoveX.^2 + MoveY.^2;
subplot(211);
plot(MoveX, MoveY,'.b','markersize',20); %--Plotted on a circle plot--%
%--Accounting for all numbers inside the circle--%
circle(t) = sum(distance(1:t) <=1);
%--Finding an estimation over set number of iterations--%
estimation = circle(1:t)./(1:t);
%--Plotting Estimation vs Iteration--%
subplot(212);
plot(estimation);
title(['N = ',num2str(t),' Estimation =', num2str(estimation(end))]);
ylabel('Estimation')
xlabel('Iteration')
end
hold on
figure(2)
clf;
syms p
bc = sin (p);
bc2 = cos (p);
Range = [0 2*pi];
subplot(211);
h = ezplot(bc,bc2,[Range]);
hold on
estimation;
scatter(circle,distance)

回答 (0 件)

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by