Welcome to Westonci.ca, your go-to destination for finding answers to all your questions. Join our expert community today! Discover precise answers to your questions from a wide range of experts on our user-friendly Q&A platform. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

We can easily improve the formula by approximating the area under the function f(x) by two equally-spaced trapezoids. Derive a formula for this approximation and implement it in a function trapezint2( f,a,b ).

Sagot :

Answer:

Explanation:

[tex]\text{This is a math function that is integrated using a trapezoidal rule } \\ \\[/tex]

[tex]\text{import math}[/tex]

def [tex]\text{trapezint2(f,a,b):}[/tex]

      [tex]\text{midPoint=(a+b)/2}[/tex]

       [tex]\text{return .5*((midPoint-a)*(f(a)+f(midPoint))+(b-midPoint)*(f(b)+f(midPoint)))}[/tex]

[tex]\text{trapezint2(math.sin,0,.5*math.pi)}[/tex]

[tex]0.9480594489685199[/tex]

[tex]trapezint2(abs,-1,1)[/tex]

[tex]1.0[/tex]

In this exercise we have to use the knowledge of computational language in python to write the code.

the code can be found in the attachment.

In this way we have that the code in python can be written as:

   h = (b-a)/float(n)

   s = 0.5*(f(a) + f(b))

   for i in range(1,n,1):

       s = s + f(a + i*h)

   return h*s

from math import exp  # or from math import *

def g(t):

   return exp(-t**4)

a = -2;  b = 2

n = 1000

result = Trapezoidal(g, a, b, n)

print result

See more about python at brainly.com/question/26104476

View image lhmarianateixeira