MATLAB Answers

I need help figuring the code out.

22 views (last 30 days)
Kelsey Dugger
Kelsey Dugger on 2 Mar 2021
Answered: Walter Roberson on 3 Mar 2021
Find the area enclosed by y = e^x , y = x, x = 0, and x = 2 please help me code this problem please
  2 Comments
Cris LaPierre
Cris LaPierre on 2 Mar 2021
You may be mistaken on what MATLAB Answers is. This is not a MATLAB coding service. We are here to answer your MATLAB questions.
If you need help getting started, consider completing MATLAB Onramp.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 3 Mar 2021
You can use a Monte Carlo method:
format long g
R = randi([2 3])
R =
3
xy = rand(10000,2) * exp(R);
x = xy(:,1); y = xy(:,2);
mask = y <= exp(x) & y >= x & x <= 2;
portion = mean(mask)
portion =
0.0121
area = portion * exp(R).^2
area =
4.88148840126209

Tags

Community Treasure Hunt

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

Start Hunting!