Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solution of - 1 1 1 - x 2 2 d x vsing PRV . 1 #question in the lecture note: 2 import numpy as

Solution of -111-x22dx vsing PRV.
1 #question in the lecture note:
2 import numpy as np
3
4n=1000000
5 success =0
6 #we make a for loop to creat a random numbers and count the success points
7
8 for i in range (n) :
9 #make random point (,yi)
10,=np.random.uni form (-1,1) #the range of x is from -1 to 1(one side of the box)
11yi=np.random.uniform (,1) #the range of x is from to 1(The other side of the box)
12,fi= np.sqrt (1-x**2),||f() function at
13 #check if yi is less than f()
14 if yi fxi:
15 success = success +1
16
17 rateOfSuccess = success ?n #success points over the total number of points
18 areaOfRectangle =2,#1*2=2 is the area of the box abf(x)dx= green aren - red area 0
19 integral = rateOfSuccess*areaOfRectangle #formula for estimation of area under the curve
20
21 print(integral)
1.57091
ofhe function has negative valre we should break the interval to two piece
one with negative value ome with possible value and make a box for each one.
abf(x)dx= green aren - red area
if the furetion is above xaais
we jist need to modity
the highlighted part of the code.-1 and 0
19 integral = rateOfSuccess*areaOfRectangle #formula for estimation of area under the curve
20
21 print(integral)
1.57091
ofhe function has negative valre we should break the interval to two piece
one with negative value ome with possible value and make a box for each one.
abf(x)dx= green aren - red area
if the furetion is above xaais
we jist need to modity
the highlighted part of the code.(Total of 6 marks) Use a random number generator in Python (e.g., numpy.random.uniform()) to ap- import numpy as np
3
4n =1000000
5 success =0
6 #we make a for loop to creat a random numbers and count the success points
7
8 for i in range(n):
9 #make random point (xi,yi)
xi = np.random.uniform(-1,1) #the range of x is from -1 to 1(one side of the box)
yi = np.random.uniform (0,1) #the range of x is from 0 to 1(The other side of the box)
fxi = np.sqrt(1-xi**2) #f(xi) function at xi
#check if yi is less than f(xi)
if yi fxi:
success = success +1
rateOfSuccess = success/n #success points over the total number of points
areaOfRectangle =2 #1*2=2 is the area of the box -1
proximate the following integral:
-223x2-6xdx.
Show your code with the result.
Hint: The function is positive on -2,0, and negative on 0,2. You should use the method taught in
class with at least 100,000 points.
Use method shown in image
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions