Question: USE MATLAB Create a function called intpoly( ) that can numerically integrate the polynomial function y = ax 2 + bx + c from a
USE MATLAB
Create a function called intpoly( ) that can numerically integrate the polynomial function y = ax2 + bx + c from a lower limit to an upper limit, where a, b, and c are constants. Your numerical integrator must allow the user to use the Trapezoidal method or Riemann sums method depending on the choice of the user. If the value of choice is 1, the Riemann sums method will be used to numerically integrate the polynomial (you may use either a left, right, or midpoint Riemann sums method). If the value of choice is 2, the Trapezoidal method will be used to numerically integrate the polynomial. The main program that calls the function intpoly( ) has the following form: % NAME, ID# % Homework 6, Problem 1 % numerically integrate y(x) = a*x^2 + b*x + c using the given % coefficients in the range defined by lowerlimit and upperlimit clear; clc; % define given parameters and number of discretizations a = 2; b = 2; c = 1; lowerlimit = 0; upperlimit = 1; N = 1000; % choice: 1 = Reimann, 2 = Trapezoidal % be sure to test both values of choice choice = 1; % call the function and display the output fprintf('Using method %i, the area is: ',choice) disp( intpoly(a,b,c,lowerlimit,upperlimit,N,choice) ) The arguments passed down to intpoly( ) are the polynomial coefficients (a,b,c), the lower and upper limits of integration (lowerlimit,upperlimit), the number of discretizations (N), and the method of integration (choice). The area is returned to the main program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
