创建区域
x=0:0.25:12
y1=x.^2;
y2=12-x;
plot(x,y1,x,y2)
xlabel(‘x’);ylabel(‘y’);
legend(‘y1=x^2’,‘y2=12-x’);
title(‘lsm绘制’);
axis([0 15 0 15]);
text(3,9,‘交点’);
grid on
撒粒子计算面积
x=unifrnd(0,12,[1,1000000000]);
y=unifrnd(0,9,[1,1000000000]);
frequency=sum(y<x.^2 & x<=3)+sum(y<12-x & x>=3)
area=129frequency/10^7
计算结果