Effacer les filtres
Effacer les filtres

Plotting results within a circle

1 vue (au cours des 30 derniers jours)
Mike
Mike le 19 Mar 2014
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)

Réponses (0)

Catégories

En savoir plus sur Visual Exploration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by