Matlab 14
Matlab 14
Objective
To understand random number generation in MATLAB and use Monte Carlo methods for numerical
integration and simulation.
Theory
Monte Carlo methods involve repeated random sampling to solve problems that may be
deterministic in nature. It is widely used in numerical integration, optimization, and simulations of
random processes.
Example Applications:
Materials Required
MATLAB Software
Procedure
2. Generate random points in the square and count those inside the circle:
pi_estimate = 4 * sum(inside_circle) / N;
figure;
axis equal;
1. Define the function f(x)=x2f(x) = x^2f(x)=x2 over the interval [0, 1].
Observations
Monte Carlo for π\piπ Estimate value of π\piπ Approximation improves with more points
Monte Carlo Integration Integrate f(x)=x2f(x) = x^2f(x)=x2 Approximates true integral value (1/3)
Conclusion
Monte Carlo methods provide an efficient way to solve problems using random sampling. With
increasing sample size, the accuracy of results improves. MATLAB simplifies the implementation with
built-in random number generation functions.
Code
pi_estimate = 4 * sum(inside_circle) / N;
% Visualization
figure;
axis equal;