Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Help limiting my Monte Carlo Solution

1 view (last 30 days)
Mike
Mike on 16 Mar 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello,
I have to write a code to determine a Monte Carlo solution for a PDE problem. The range goes from zero to pi and the limiting factor is the sin wave. My problem that i am experiencing is that my current code stops at on and not the limit of the sin wave. Can someone take a look at the code and see where i made my mistake?
clear; clc;
n = 1000;
x = linspace(0,1,n);
Xinside = [];
dist_X = [];
figure(1)
clf;
syms p
bc = sin (p);
Range = [0 pi];
h = ezplot(bc,Range);
hold on
distance = zeros(0,1,n);
for t = 1:n
a = 0;
b = 1;
Xn = a + b*rand();
Xn(t) = (Xn + Xn)<=1;
plot(Xn);
%distance(t) = sum(distance(1:t) <=1);
%est_pi = 4*Xinside(1:t)./(1:t);
%plot(est_pi);
ylabel('estimation')
xlabel('iteration')
end
hold off

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!