I have the following code and would like to plot the approximation "integ" with respect to the number of tries "N": how do I do that?
%function that evaluates the integral of e^sin(x)
%using Monte Carlo
clc; clear;
e=exp(sin(1.0));
rand('state',0);
%generating random number with the sequence reproducible
ssum=0;
%calculate the function of a total of 1000 times
for i=1:100
for j=1:10
x=rand;
ssum=ssum+exp(sin(x));
end
N=i*10;
integ=ssum/N;
end

 採用された回答

Walter Roberson
Walter Roberson 2015 年 10 月 6 日

0 投票

Change
integ=ssum/N;
to
integ(i) = ssum/N;
Then after the loop,
plot(integ)

1 件のコメント

Thomas Chateauvert
Thomas Chateauvert 2015 年 10 月 6 日
Thank you very much Mr. Robertson.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by