Question: Anonymous Functions and Function Handles. Remember to write text that ex - plains your solution and introduces all code and output that you include. This

Anonymous Functions and Function Handles. Remember to write text that ex- plains your solution and introduces all code and output that you include. This text should come first, before all code and output.
First write a function simp(f, a, b, n) which uses Simpsons rule
Zbhh i
f(x)dx3 f(x0)+4f(x1)+2f(x2)+4f(x3)++2f(xn2)+4f(xn1)+f(xn), a
where h = ba denotes the numerical step size for a given even integer n, to approximate the n
definite integral of f(x) over the interval [a,b]. The implementation of the function will be very similar to that of trap.m we saw in the tutorial. Next, write a script file in which which you will define the functions
f(x)= sin(x) x in [0,\pi 2] g(x)= ecos(x) x in [0,\pi ]
as anonymous functions and then use simp to compute the definite integral of each function over the given interval. Use n =4,8,16,32,...,512 and print a table as follows:
n I(f) I(g)
------------------------------
41.09734946
81.11043794
161.11503637
321.11665656
.
..
3.97173128
3.97746305
3.97746326
3.97746326
You should note that the formula for Simpsons rule has a similar pattern to Homework 2 Problem 3. Consider incorporating your solution from there into this problem.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!