Question: MATLAB Part 2: Numerical Integral Save your file as integral.m Create a function with the headerline function integral(x, y) Where x and y are vectors

MATLAB

MATLAB Part 2: Numerical Integral Save your file as integral.m Create a

Part 2: Numerical Integral Save your file as integral.m Create a function with the headerline function integral(x, y) Where x and y are vectors and x has a step size of h Your function should numerically estimate the integral from a to b of y (where a is the first value in the x-vector and b is the last value) using the following methods Rectangular using the left hand value - Rectangular using the right hand value - Trapezoidal You may not use any of MATLAB's built in functions for integrals, but you may use the sum() function. If x is a vector, sum(x) will sum all of the entries in the vector Your function should print out your solutions using the lines of code fprintf(I'In the integral using the left Riemann sum is 'num2str(left)]) fprintf(['In the integral using the right Riemann sum is num2str(right)]) fprintf(I'In the integral using the trapezoid sum is num2str(trap) 'In']) Test your function: >>y exp(-x.A2); >> integral(x,y); the integral using the left Riemann sum is 0.83623 the integral using the right Riemann sum is 0.93623 the integral using the trapezoid sum is .88623

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!