%function [int_ft] = gerberdolan_jessica_hw09_int(t, f)
%INPUT:
%t = vector of t values at which the function is provided
%f = vector of values of the function at the points contained in t
%OUTPUT:
%int_ft = value of integral
%start this function as a script with the following test senario
t = [0 pi/4 pi/2 3*pi/4 pi]f = cos(t)+5for i = 1:(length(t)-1)t = t(i);r(i) = f(i).*(t(i+1)-t(i))%((t(1+1)-t(i)) is delta x
%f(t(i)) is the base rantagle for the retangular rule
%r is rectangle
tr(i) = (f(t(i))-f(t(i+1)))*(t(1+1)-t(i))*1/2%tr is the triangle on top
%(f(t(i))-f(t(i+1))) is the height difference
%(t(1+1)-t(i)) is delta x
%1/2 is to make it a triangle
a_of_trap(i) = r(i) + tr(i)%area of trapizoid is the rectangle plus the triangle
endint_ft = sum(a_of_trap)
MATLAB: I keep getting ‘Index exceeds array bounds.’ the code doesn’t like r(i)
array boundserrorerror message
Best Answer