Question

Write MATLAB code that uses Monte Carlo integration for estimating
cb sin(da

where a = -2 and b = 2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab code :

func = @(x) sin(.*x).^2 ; % Given function

a = -2

b = 2

integral (func, a, b)

NoOfSample = 10000 ;

r = (b-a).*rand(1000,1) + a; % Generate random number of array size 10000 in range -2 to 2

rf = 4.0 * func (r); % normalized function

mean = mean (rf) ; % calculating mean of function

error = std (rf) / sqrt (Nsample) ; % computing error

fprintf ( 'Monte Carlo estimate (Nsample=%d) %f +/- %f \n' , NoOfSample, mean, error);

Add a comment
Know the answer?
Add Answer to:
Write MATLAB code that uses Monte Carlo integration for estimating where a = -2 and b...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT