Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the blocks of code below. Match each labelled line of code with the statement that best describes its purpose. import numpy as np import

Consider the blocks of code below. Match each labelled line of code with the statement that best describes its purpose. import numpy as np import numpy.random as nrand ( operatorname{def} ) integrationA( ( f, a, b, n) ) : ( mathrm{dx}=(mathrm{b}-mathrm{a}) / mathrm{n} quad ) ## (a) ( mathrm{x}=mathrm{np} ). linspace ( (mathrm{a}, mathrm{b}, mathrm{n}+1) quad ) # (b) ( y=f(x) quad # ) (c) return ( n p cdot operatorname{sum}(y[ heta: n]) * d x quad ) ## (d) def integrationB( ( f, a, b, n) ) : ( d x=(b-a) / n ) ( x=n p ). linspace ( (a, b, n+1) ) ( y=f(x) ) return ( n p cdot operatorname{sum}(y[1: n+1]) * d x ) ## (e) def integrationc ( (f, a, b, n) ) : ( mathrm{dx}=(mathrm{b}-mathrm{a}) / mathrm{n} ) ( x=a+(b-a) * n r a n d cdot r a n d o m(n) quad #(f) ) ( y=f(x) quad ) ## (g) return ( n p cdot operatorname{sum}(y) * d x quad #(h) ) (1) Creates an array of ( n+1 y )-values, where ( y=f(x) ). (2) Creates an array of ( n+1 ) equally spaced values between ( a ) and ( b ), inclusive. (3) Creates an array of randomly chosen values between ( a ) and ( b ), inclusive. (4) Computes the Monte Carlo approximation of the definite integral of ( f ) on ( [a, b] ). (5) Creates an array of ( n y )-values, where ( y=f(x) ). (6) Computes the right Riemann sum approximation of the definite integral of ( f ) on ( [a, b] ). (7) Defines the width of each approximating rectangle. (8) Computes the left Riemann sum approximation of the definite integral of ( f ) on ( [a, b] ). So, for example, if you think that (a) matches (3), (b) matches (5), (c) matches (1), (d) matches (2), (e) matches (7), (f) matches (4), (g) matches (5), and (h) matches (6), then you would enter ( 3,5,1,2,7,4,5,6 ) into the answer box below.
image text in transcribed
2: Consider the blocks of code below: Match each labelled line of code with the statement that best describes its purpose. import numpy as np import numpy.random as nrand def integration A(f,a,b,n) : dx=(ba) sit (a) x=np. linspace (a,b,n+1) and (b) y=f(x), "in (c) return npsun(y[9:n])dx as (d) def integrationB (f,a,b,n) : dx=(ba) x=np.1 inspace (a,b,n+1) y=f(x) return np+sin(y[11n+1])dx=n=(e) def integrationc (f,a,b,n) : dx=(ba) x=a+(ba) "nrand.randoen( n) win (f) y=f(x) oin (g) return np+sun(y)dx sin (h) (1) Creates an array of n+1y-values, where y=f(x). (2) Creates an array of n+1 equally spaced values between a and b, inclusive. (3) Creates an array of randomly chosen values between a and b, inclusive. (4) Computes the Monte Carlo approximation of the definite integral of f on [a,b]. (5) Creates an array of ny-values, where y=f(x). (6) Computes the right Riemann sum approximation of the definite integral of f on [a,b]. (7) Defines the width of each approximating rectangle. (8) Computes the left Riemann sum approximation of the definite integral of f on [a,b]. So, for example, if you think that (a) matches (3), (b) matches (5), (c) matches (1), (d) matches (2). (e) matches (7), (f) matches (4), (g) matches (5), and (h) matches (6), then you would enter 3, 5, 1, 2, 7, 4, 5, 6 into the answer box below. 2: Consider the blocks of code below: Match each labelled line of code with the statement that best describes its purpose. import numpy as np import numpy.random as nrand def integration A(f,a,b,n) : dx=(ba) sit (a) x=np. linspace (a,b,n+1) and (b) y=f(x), "in (c) return npsun(y[9:n])dx as (d) def integrationB (f,a,b,n) : dx=(ba) x=np.1 inspace (a,b,n+1) y=f(x) return np+sin(y[11n+1])dx=n=(e) def integrationc (f,a,b,n) : dx=(ba) x=a+(ba) "nrand.randoen( n) win (f) y=f(x) oin (g) return np+sun(y)dx sin (h) (1) Creates an array of n+1y-values, where y=f(x). (2) Creates an array of n+1 equally spaced values between a and b, inclusive. (3) Creates an array of randomly chosen values between a and b, inclusive. (4) Computes the Monte Carlo approximation of the definite integral of f on [a,b]. (5) Creates an array of ny-values, where y=f(x). (6) Computes the right Riemann sum approximation of the definite integral of f on [a,b]. (7) Defines the width of each approximating rectangle. (8) Computes the left Riemann sum approximation of the definite integral of f on [a,b]. So, for example, if you think that (a) matches (3), (b) matches (5), (c) matches (1), (d) matches (2). (e) matches (7), (f) matches (4), (g) matches (5), and (h) matches (6), then you would enter 3, 5, 1, 2, 7, 4, 5, 6 into the answer box below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions