Question: Matlab please TRAPEZOIDAL INTEGRATION PROGRAM (example of a function of a function) We now construct an m-file to do trapezoidal integration. % This program estimates
TRAPEZOIDAL INTEGRATION PROGRAM (example of a function of a function) We now construct an m-file to do trapezoidal integration. % This program estimates area under curve using trapezoids % using a specified n number of trapezoids, over the limits a to b, the function is func! >> type area 1 function y = area 1 (func, a, b, n) total = 0; base = (b-a); for k = 2:n xk = a + base* (k-1); total = total + feval(func, xk); end y = 0.5.* base.* (feval (func, a) + 2.0.* total + feval(func, b)); Recall function humps >>type humps function y = humps(x) % Humps(x) is a function used by QUADDEMO and ZERODEMO. Y = 1./((x-.3).^2 + .01) + 1 ./((x-.9).^2 + .04) - 6; a) write a short m-file that will call upon the function and integrate it from 0 to 1 both by first constructing of function area 1.m as above, using 100 trapezoids and then calling on the built in quad function to get the area. b) The also plots humps from 0 to 1 very finely with 100 values of x. Integration fun. a. set up a function file for y(x) = 34 exp(-0.2x) sin(3x + pi/8) call it whatever you want. In one m-file do the following b. Integrate this function from 0 to 30 using the quad()functions. c. use area 1() to integrate this function. d. Plot the function over the interval in steps of 0.01: Do a rough estimate of the area from the plot. e. Compare the integrations over the same interval. Which is probably the best answer. Why? Or why not
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
