(Numerical Integration) Suppose we are given a function f(x) whose integral is not known explicitly. We may, however, wish to still approximate the value of the definite integral of f over the interval [a, b]. In order to do this, we could use the so-called composite trapezoid rule with n+1 nodes given by T-1 h Ls(2) dz = (s(a) + 2 fla + kh) + f(b)). k=1 where h = b-a comp_trap_rule Function: Input variables: • an anonymous function representing f • a scalar representing the lower bound of integration a • a scalar representing the upper bound of integration b • a scalar representing the value of n; you may assume this is an integer greater than 0 Output variables: • a scalar represcnting the approximate integral computed by the formula above A possible sample case is: » int = comp_trap_rule(@(x) x^2, 0, 1, 100) int 0.33335 %3!

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.7: Do While Loops
Problem 6E: (Numerical analysis) Here’s a challenging problem for those who know a little calculus. The...
icon
Related questions
Question

make mathlab code 

(Numerical Integration) Suppose we are given a function f(x) whose integral is not
known explicitly. We may, however, wish to still approximate the value of the definite
integral of f over the interval [a, b). In order to do this, we could use the so-called
composite trapezoid rule with n+1 nodes given by
h
n-1
[S(2) dzx = (5(a) +2E f(a + kh) +,
+2Ef(a + kh) + f(b
k=1
where h = b-a
comp_trap_rule Function:
Input variables:
• an anonymous function representing f
• a scalar representing the lower bound of integration a
• a scalar representing the upper bound of integration b
• a scalar representing the value of n; you may assune this is an integer
greater than 0
Output variables:
• a scalar representing the approximate integral computed by the formula
above
A possible sample case is:
> int = comp_trap_rule(@(x) x^2, 0, 1, 100)
int =
0.33335
Transcribed Image Text:(Numerical Integration) Suppose we are given a function f(x) whose integral is not known explicitly. We may, however, wish to still approximate the value of the definite integral of f over the interval [a, b). In order to do this, we could use the so-called composite trapezoid rule with n+1 nodes given by h n-1 [S(2) dzx = (5(a) +2E f(a + kh) +, +2Ef(a + kh) + f(b k=1 where h = b-a comp_trap_rule Function: Input variables: • an anonymous function representing f • a scalar representing the lower bound of integration a • a scalar representing the upper bound of integration b • a scalar representing the value of n; you may assune this is an integer greater than 0 Output variables: • a scalar representing the approximate integral computed by the formula above A possible sample case is: > int = comp_trap_rule(@(x) x^2, 0, 1, 100) int = 0.33335
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr