Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a MATLAB function: Homework Problem 3: Numerical Integration with Simpson's Rule In this exercise, you will create a function to compute definite integrals using

Create a MATLAB function:

image text in transcribedimage text in transcribed

Homework Problem 3: Numerical Integration with Simpson's Rule In this exercise, you will create a function to compute definite integrals using Simpson's rule and the com posite Simpson's rule. For an interval of integration [a, b, Simpson's rule approximates the definite integral of f(r) by (13) Divide [a, into n equal subintervals of length h to obtain the composite Simpson's rule n/2-1 rn (14) where xj = a+jh and h = (b-a). Note that n need to be even 1. Write a function called Simpson to evaluate the definite integral of a given function f(x) on an interval [a, b. You must follow the pseudo-code: function [I,h] - Simpson (f,a,b,tol) %SIMPSON Compute definite integral of function using composite Simpson rule % 1 Simpson (f,a,b,tol) takes as inputs anonymous function f, the limits % of the interval of integration [a,b] and tolerance tol. Output is the % definite integral 1 and subinterval length h Initialization Set n = 2 and use Eq. (13) to compute a first approximation 101d Repeat Set 101d = 1 Double n and compute I with Eq. (14) Stop when tol You should run a few tests with Simpson to make sure it works properly. For exarnple, if f(z) = cos(2), then cos(a)dx - sins sin(0) = 1 In this case, your function should return >> [t-simp ,h] = Simpson (0(x) cos (x) ,0,pi/2 ,10-3) t-simp = 1.0000 0.1963 >> t-simp-1 ans 8.2955e-06 % error Homework Problem 3: Numerical Integration with Simpson's Rule In this exercise, you will create a function to compute definite integrals using Simpson's rule and the com posite Simpson's rule. For an interval of integration [a, b, Simpson's rule approximates the definite integral of f(r) by (13) Divide [a, into n equal subintervals of length h to obtain the composite Simpson's rule n/2-1 rn (14) where xj = a+jh and h = (b-a). Note that n need to be even 1. Write a function called Simpson to evaluate the definite integral of a given function f(x) on an interval [a, b. You must follow the pseudo-code: function [I,h] - Simpson (f,a,b,tol) %SIMPSON Compute definite integral of function using composite Simpson rule % 1 Simpson (f,a,b,tol) takes as inputs anonymous function f, the limits % of the interval of integration [a,b] and tolerance tol. Output is the % definite integral 1 and subinterval length h Initialization Set n = 2 and use Eq. (13) to compute a first approximation 101d Repeat Set 101d = 1 Double n and compute I with Eq. (14) Stop when tol You should run a few tests with Simpson to make sure it works properly. For exarnple, if f(z) = cos(2), then cos(a)dx - sins sin(0) = 1 In this case, your function should return >> [t-simp ,h] = Simpson (0(x) cos (x) ,0,pi/2 ,10-3) t-simp = 1.0000 0.1963 >> t-simp-1 ans 8.2955e-06 % error

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Discuss the challenges in scanning the environment.

Answered: 1 week ago

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago