Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 Consider the following integral of a function f(r) on a finite interval [a, Write three Matlab/Octave functions implementing, respectively, the composite midpoint rule,

image text in transcribed

Exercise 1 Consider the following integral of a function f(r) on a finite interval [a, Write three Matlab/Octave functions implementing, respectively, the composite midpoint rule, the composite trapezoidal rule, and the composite Simpson rule to compute the numerical approxima- tion of I(f). Such functions should be of the form function [I]-intmidpoint.rule(fun,a,b,n)(composite midpoint rule) function [Il-int.trapezoidal.rule(fun,a,b,n) (composite trapezoidal rule) function [1]=int.Simpson-rule (fun , a,b,n) (composite Simpson rule) Input fun: function handle representing f(x) a, b: endpoints of the integr n: number of evenly-spaced points m [a, ation interval (including endpoints) Output: I: numerical approximation of the integral (1) Exercise 2 Use the functions you coded in Exercise 1 to compute the numerical approximation of the integral To this end, write a Matlab/Octave function [en,et ,es] function test-integration() that returns the following items: . en, ot, es: row vectors with components the absolute values of the integration errors |ref-1.1 Inl2,3. 10000 n=2.3. 1 obtained with the midpont (vector en). trapezoidal (vector et) and Simpson (vector es) rules. Here Iref = 1.6851344770476 is the reference value of the integral (2) while In is the nucal approximation obtained by using the composite midpoint, trapezoidal, and Simpson rules with nnodes The function test.integrationO should also return the plot of the integrand function ap- pearing in (2 in figure(1), and the plots of the errors en, et and es versus n in a log-log scale in figure (2) (one figure with three plots). (Hint:us the Matlab command loglog))

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions