%% Simulation of continuous probability densities %% Plot of random points in the unit square % I'll plot 1000 random points in the unit using the command *scatter* to % plot the points. If I give the command *scatter(x,y)* the points will be % fairly large. So I'll give a third argument, designed to make them large % enough to see but not too large. n=10^3 x=rand(1,n); y=rand(1,n); scatter(x,y,3) %% Plot of random points and a curve % I'll plot again, adding the curve $y=\sin(x)$ to the plot. I'll use the % *plot* command to plot it, after creating a vector X of points at which % to plot it. n=10^3 x=rand(1,n); y=rand(1,n); scatter(x,y,3) hold on X = 0:0.001:1; plot(X,sin(pi*X),'r','LineWidth',2) hold off %% Monte Carlo simulation % This is used to estimate an integral. Here I use it to estimate the % integral of sin(pi*x), 0