Question: 1. Write a function MyTrapezoidQuad that takes as inputs a function f and an array of values xs with spacing h between them. The
1. Write a function MyTrapezoidQuad that takes as inputs a function f and an array of values xs with spacing h between them. The function should return the approximated integral of f over the interval (zo...) using the trapezoid rule on the given points. Hint: Use the pseudocode in Listing 1 to write your function. Use your Matlab function to approximate the integral of: A= - [ e cos(x)dr = (e$ - 1) Jo using n=2,4,8, 16, 32, 64, 128, 256 subintervals (h= 20=). Re- port the results of your approximation in a table with columns: " n the number of subintervals T(h) - the approximated integral values using Trapezoid rule En the absolute error |A-T(h)| -the error ratio (where=1 Hint: Since Trapezoid rule is order 2 in h, your error should decrease by a factor of 4, (22), when you double n.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
