I have to create a monte carlo integration of the function above and this is what i've tried so far;
function monte_carlo = Task_2_monte_carlo(t)f = @(t) (-0.1).*(t.^3) + (0.58).*(t.^2).*(cosh((-1)./(t+1))) + exp((t)./(2.7)) + 9.6;n = rand(10,1); %deze waardes moeten in de domain van f passen
upper_lim = 12;lower_lim = 0;y_max = 200;N = 1000; %total number of points
N0 = 66; %number of points underneath the graph
y = (10/n).*(y_max.*(upper_lim - lower_lim))monte_carlo = sum(y);plot(n,y); hold on;end
This gives me 2 straight lines but I am struggeling to translate this into the correct monte carlo formation. I have succeeded in creating a random graph of poitns which one would need but can't seem to get it coded into the function above, namely;
function monte_carlo = Task_2_monte_carlo_2(t)f = @(t)(-0.1).*(t.^3) + (0.58).*(t.^2).*(cosh((-1)./(t+1))) + exp((t)./(2.7)) + 9.6;%yt = sort(rand(2, N)), 1, 'descend');
%t = 12*yt(1.:);
n = rand(10,1); %deze waardes moeten in de domain van f passenN = 1000; %total number of pointst = 12*rand(1, N); %domain x = [0,12]
y = 200*rand(1, N); %y = [0,200]
plot(t,y,'.')y_max = 200; %N0 = ; %number of pointa underneed the graph
y1 = (n_max/n).*(y_max.*(max(t) - min(t)))monte_carlo = sum(y1);end
If someone can help or point me in the right direction it would be much appreciated!
Best Answer