
integration matlab qn
1. The problem statement, all variables and given/known data
Let us consider an approximation to an integral. Let f(x) be some continuous function on
[a, b]. We wish to find an approximation for the integral
I = int from a to b of f(x)dx
in the following manner:
Subdivide the interval into N intervals of length h = (b−a)/N. Let xi = ih for i = 0, . . . ,N.
Let
Ij = int from 0 to h of f(xj+t)dt
Find a cubic polynomial Pj (x) that goes through (xj , f(xj)), (xj + h/3,f(xj + h/3)),(xj+2h/3, f(xj+2h/3) and (xj+1,f(xj+1))
We form an approximation for the integral by letting
I=sum(j=0 to N1) of w0*f(xj)+w1*f(xj+h/3)+w2*f(xj+2h/3)+w3*f(xj+1)
Find these weights, wi.
In 2 peices of code, plot the first three Bessel functions, J0(x), J1(x) and J2(x), on the
interval [0, 20]. The first peice of code should be a MATLAB function BJ(x, n) outputing
the approximation for the integral representation of Jn, given by
Jn(x) =(1/pi)int from 0 to pi of cos(nt − x sin t)dt
using the above method for 100 subdivisions of [0, pi]. The second peice of code should call
the function an produce the required plots with 2000 subdivisions of [0, 20].
Im just gobsmacked with this qn.. as i only started using matlab a couple of days, ago and have no programming experience.
what i have done so far is really no good, but i have no idea.
function [Jn]=BJ(x,n)
N=100;
b=pi;
a=0
h=(ba)/N;
x=a:h:b;
xj=i*h;
Ij=0;
J0=cos(n*xjx*sin(xj));
J1=cos(n*(xj+h/3)x*sin(xj+h/3));
J2=cos(n*(xj+(2*h/3))x*sin(xj+(2*h/3)));
J3=cos(n*(xj+1)x*sin(xj+1));
for i=0:N;
Ij=Ij+w0*J0+w1*J1+w2*J2+w3*J3;
J=(1/pi)*Ij;
end
can someone please help me

my lecturer told me this... when i asked for help... but have no idea what it means, or what he has done
The trick about finding the weights is to consider the Polynomial of
degree 3 of the form
P(x) = f(xj) P_0(x) + P_1(x)f(xj + h/3) + P_2(x)f(xj + 2h/3) P_3(x)f(xj + h)
dont try ax^3 + bx^2 + cx + d, that derivation is many many pages
long, and we require a trick from polynomial interpolation to avoid
complications. It is a trick we used in one of the derivations of
simpsons rule.
Now, we can transform this integral to one over 0 to h, which just
simplifies the calculations to a page or two less. P_i are all of
degree 3 and
P(0) = f(xj)
P(h/3) = f(xj+h/3)
P(2h/3) = f(xj+2h/3)
P(h) = f(xj + h)
this defines the polynomials completely as
P_0(0) = 1 and P_1(0) = P_2(0) = P_3(0) = 0
P_1(h/3) = 1 and P_0(h/3) = P_2(h/3) = P_3(h/3) = 0
P_2(2h/3) = 1 and P_0(2h/3) = P_1(2h/3) = P_3(2h/3) = 0
P_3(h) = 1 and P_0(h) = P_1(h) = P_3(h) = 0
these define the P_i completely since you know each polynomials roots.
Now w_i is the integral of P_j over 0 to h. This is exactly like what
we did for Simpsons rule.

ok I looked through it and i got..
P_0=(0,1),(h/3,0),(2h/3,0),(h,0)
P_1=(0,0),(h/3,1),(2h/3,0),(h,0)
P_2=(0,0),(h/3,0),(2h/3,1),(h,0)
P_3=(0,0),(h/3,0),(2h/3,0),(h,1)
is that right?

is it something like Simpson's 3/8 rule?? i just wiki'd and since its interpolated with a cubic instead of a quadratic, it mite be that? But how do i derive the rule from what i have? or even better code it?

ok from Pj(x).. and integrating over 0 to h i got
h/8*P_0+3h/8*P_1+3h/8*P_2+h/8*P_3 this is really i close i think.. but not sure, please can anyone help?