Im having trouble understanding what is wrong with my program, it is intended to integrate the following expression (contained on the link) using the trapezium rule:
and it is bounded by the values pi and 0.
My program obtains the results 6.1295 when using my trapezium rule, and 4.6979 when it is done analytically.
It works for simple expressions i.e. sin (x) but for some reason it doesnt like this more complicated expression. I believe the error to be because of the 'P' in my expression but im unsure how to solve this, if this is the problem. Here is my program thus far:
Any help would be greatly appreciated!!n=100 %number of intervals
b=pi % upper bound
a=0 %lower bound
I=(h/2)*( f(a,P) + f(b,P) ) + h*sum(f(a+i*h,P))
Iexact01= - (cos(2*P*pi*x) + 2*P*pi*x*(sin(2*P*pi*x) - P*pi*x))/(4*(P^2)*(pi^2));
Iexact02= - (cos(2*P*pi*x) + 2*P*pi*x*(sin(2*P*pi*x) - P*pi*x))/(4*(P^2)*(pi^2));
Iexact = Iexact01 - Iexact02