Mininum of a function using Monte Carlo -...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
a=0; r=0; for i=0:1:2000 x=(2*rand()-1)*200; y=(2*rand()-1)*200; deltax=(2*rand()-1)*10; deltay=(2*rand()-1)*10; f0=(x^2-3*x*y-2*x+y-2*y^2+180)*exp(-(x^2+y^2)/1000); f1=((x+deltax)^2-3*(x+deltax)*(y+deltay)-2*(x+deltax)+(y+deltay)-
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2*(y+deltay)^2+180)*exp(-((x+deltax)^2+(y+deltay)^2)/1000); if f1<f0 x=x+deltax; y=y+deltay; a=a+1; else if exp(f0)/exp(f1)>rand() x=x+deltax; y=y+deltay; else x=x; y=y; end r=r+1; end end x y a r...
View Full Document

This note was uploaded on 05/18/2011 for the course PHYSICS 100 taught by Professor Bayas during the Spring '11 term at Instituto Politecnico National Escuela Superior de.

Ask a homework question - tutors are online