Go Back

Approximate value of √2 using 1000 random numbers and Monte Carlo Simulation

Hits

Posted on 04 Nov 2018


for i=1:1000
  x=grand(1,1,"unf",0,2)
  f=x*x
  if sign(2-f)==1 then
      count=count+1
  end
end

z=(count/1000.0)*2
disp("Approximate value of root 2 is ",z)```