Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use matlab to write this script Question 1 (10 Points) Write a MATLAB function t

ID: 2248360 • Letter: U

Question


Use matlab to write this script

Question 1 (10 Points) Write a MATLAB function to implement the Trapezoidal Method of Integration. Use the function prototype: function y atrap(fn, a, b, h), where fn is the function handle that describes the function to integrate. The limits of integration are a and b. And the step size is specified as h. This method is illustrated below. fix) f(x2) f(x) X. Fuset.ion ia called troa the comsand 1ine aftor an nfaned * >> trar(f, D,4,0.1] ovaluatou integral fr n nt. 4

Explanation / Answer

clc; clear all; close all; f=@(x)1/(1+x); %Change here for different function a=0;b=6; %Given limits n=b-a; %Number of intervals h=(b-a)/n; p=0; for i=a:b p=p+1; x(p)=i; y(p)=1/(1+i); %Change here for different function end l=length(x); x y answer=(h/2)*((y(1)+y(l))+2*(sum(y)-y(1)-y(l)))