%% Lecture 3, Exercise 1, Circle data

close all
x=linspace(-4,4,100);
y=x;
[X,Y]=meshgrid(x,y);
Z=X.^2+Y.^2;
in=Z<=2;
mesh(x,y,in)
axis square
%%
figure
%imagesc(in)
plot(X(in),Y(in),'.')
axis square
%% Here are some "starter" hints for Credit exe 6
%
% Start with short vectors to learn the idea.
x=2*rand(1,20)-1;  %Rand nrs. on [-1,1]
y=2*rand(1,20)-1;  % Another random sequence.
% Which ((x(i),y(i)) coordinates are inside the unit circle?
in=x.^2+y.^2 <=1   % This logical vector reveals it.
% Use this logical vector to index x and y.
% See, to understand:
in
[x(in)' y(in)']
x(in).^2 + y(in).^2   % Are the points really in?
out=~in
x(out).^2 + y(out).^2  % Are the points really out?
%% Now do the real business (remember semicolons):
x=2*rand(1,1000)-1;  %Rand nrs. on [-1,1]
y=2*rand(1,1000)-1;
in=x.^2+y.^2 <=1;
sum(in)
% For your calculation (and graphics) you can take longer vectors.
% Increase gradually.
plot(x(in),y(in),'.')
axis square
hold on
t=linspace(0,2*pi);
plot(cos(t),sin(t))