Create a function called intpoly that can numerically integr

Create a function called intpoly() that can numerically integrate the polynomial function y = ax^2 + 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 (as we used in discussion) 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 calls the function intpoly() and has the following form: % numerically integrate y(x) = ax^2 + bx + c from lowerlimit to upperlimit 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.

Solution

function [ answer ] = intpoly( a,b,c,lowerlimit,upperlimit,N,choice )
if(choice==1)
    f=@(x)a*x^2+b*x+c;
    value = 0;
    dx = (upperlimit-lowerlimit)/N;
    for k=1:N
    c = lowerlimit+k*dx;
    value = value + f(c);
    end
    value = dx*value;
    disp(value);
elseif(choice==2)
    f=@(x)a*x^2+b*x+c;
    h=(upperlimit-lowerlimit)/N;
    p=0;
    for i=lowerlimit:h:upperlimit
    p=p+1;
    x(p)=i;
    y(p)=f(i); %Change here for different function
    end
    l=length(x);
    answer =(h/2)*((y(1)+y(l))+2*(sum(y)-y(1)-y(l)));
end
end

 Create a function called intpoly() that can numerically integrate the polynomial function y = ax^2 + bx + c from a lower limit to an upper limit, where a, b, a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site