- #1

- 763

- 0

## Homework Statement

Write an algorithm and Matlab function JN, which uses the Composite Trapez-

ium Rule (CTR) to compute an approximation of the integral f(x) dx for an arbitrary

function f of one variable. The inputs should be a, b and N (the number of

subintervals), and f (the name of a Matlab function of one variable). The

output should be the approximate integral value JNf, i.e. the result of the

Composite Trapezium Rule for f.

## Homework Equations

## The Attempt at a Solution

function JN=CTR(a,b,N)

h=(b-a)/N;

JN=0;

for i=1:N

ti=a+i*h;

ti1=a+(i-1)*h;

f=f(ti);

JN=JN+h/2*(f(ti1)+f(ti))

end

Most of it looks right but i'm sure i have done something wrong. is there something missing with defining f.

Thank you