Bessel functions

Plot of the Bessel function of the first kind of order 0:

Plot[BesselJ[0, x], {x, 0, 10}]

Plot of the Bessel function of the first kind of order 1:

Plot[BesselJ[1, x], {x, 0, 20}]

Plot of the Bessel function of the second kind of order 0:

Plot[BesselY[0, x], {x, 0, 20}]

A few Mathematica list tools

mylist = {1, 2, {4, 7}, 5}

Length[mylist]

mylist[[3, 2]]

Range[0, 2. , 1/2]

Range[0, 2, 0.5]

Table[k^2, {k, 0, 2, 0.5}]

Lagrange polynomial example

Plot[Exp[-x^2], {x, 0, 2}]

The following procedure generates the Lagrange interpolating polynomial for the points with x values given in xlist and y values given in ylist.  As given, ylist is generated by applying a function to the values in xlist.  You could also enter values for ylist by hand.

Clear[f, x, p, l];
f[x_] = Exp[-x^2];
xlist = {0, 1, 2};
ylist = f[xlist];
n = Length[xlist];
l[k_, x_] := 
        Product[(x - xlist[[i]])/(xlist[[k]] - 
                  xlist[[i]]), {i, 1, 
              k - 1}]*
Product[(x - 
                  xlist[[i]])/(xlist[[k]] - 
                  xlist[[i]]), {i, k + 1, 
              n}];
p[x_] = Sum[ylist[[k]]*l[k, x], {k, 1, n}];

We can look at the polynomial.

p[x]

The Collect function reorganizes the polynomial by degree on x.

Collect[p[x], x]

To compare, we plot f and p on the same axes.

Plot[{f[x], p[x]}, {x, -0. , 2. }, 
      PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 0, 1]}]

We can use the polynomial to approximate outputs for f away from the points used to generate the polynomial.

p[0.75]

For comparison, here is Mathematica's value for the function at this input.

f[0.75]

Later, we will use this type of polynomial in approximating definite integrals.  Because the interpolating function is a polynomial, we can easily compute a definite integral (although we will let Mathematica do this for us here.)

Integrate[p[x], {x, 0, 2. }]

For comparison, here is Mathematica's approximation for this definite integral.

NIntegrate[f[x], {x, 0, 2. }]