(adsbygoogle = window.adsbygoogle || []).push({}); 1. The problem statement, all variables and given/known data

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.

2. Relevant equations

3. 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

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab function

**Physics Forums | Science Articles, Homework Help, Discussion**