Question: Please write the MATLAB script to answer the question Function file of SimpsonSum script file (please do not change this function file: function [Area] =
Please write the MATLAB script to answer the question
Function file of SimpsonSum script file (please do not change this function file:
function [Area] = SimpsonSum(f,a,b,nSamples) % Do not change this function (for use with ENGR112 HW7) % Function Inputs: % f = The equation to be integrated (as a function) % a = The lower limit of integration % b = The upper limit of integration % nSamples = Number of evenly-space samples to take from the function % Function Outputs: % Area = Area bounded by the function, limits of integration, and x- % axis
% Equation: % Area = (dx/3) * sum(y_0+4y_1+2y_2+...+2y_(n-2)+4y_(n-1)+y_n) % (underscores indicate subscipts) % dx is the distance between samples, % y is the value of the function evaluated at each sample % n is the number of samples - 1 (because n starts at 0 instead of 1)
%Take evenly-spaced samples over the integration interval xs = linspace(a,b,nSamples); ys = f(xs);
%Find x interval between samples (used to calculate Area) dx = xs(2)-xs(1);
%Apply weights to each term ys(2:2:end-1) = 4 * ys(2:2:end-1); ys(3:2:end-2) = 2 * ys(3:2:end-2);
%Calculate Area Area = (dx/3) * sum(ys);

![SimpsonSum script file (please do not change this function file: function [Area]](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f532758e764_26866f53274c9261.jpg)


Thank you for the help!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
