Vector calculation of HermiteH Polynomials
12 views (last 30 days)
Show older comments
The function im trying to code is hermiteH and it is as follows:

I want to create a vector of n hermite polynomials, and then each one to go through
, some sort of matrix operation comes to mind but the implementation eludes me.

My goal is to get something like
be run through
.
In the example ill get
with
.
My current Code:
Hk = @(k,x) hermiteH(k,x/sqrt(2))*2.^(-k/2);
k = 2;
hPoly = zeros(1,k+1);
for i=1:k
hPoly = hPoly + Hk(i,[0 1 2]);
end
hPoly
The code is Not right.
- The MATLAB hermiteH is the "physicist's Hermite polynomials" (i.e.
) and not the "probabilist's Hermite polynomials" (i.e.
) I'm looking for but I "fixed" it with the extra "
" term, but I'm not sure. - The result is wrong and I cant get it right.
- The end goal is to implement the Wolfram syntax into a functional MATLAB code with k and x variables. note: to make multiple polynomials in one vector with the hermiteH command it requires k to be a vector (i.e. 1:7) and x to be symbolic so basically k is a vector and x is a vector and make the implementation versetile.
- The problem I think is the first term in the result adds the first Hermite k times, the second Hermite k-1 times and so on...
Any advice on the matter is much obliged.
4 Comments
John D'Errico
on 17 Jan 2023
conv is the classic MATLAB trick for multiplication of polynomials or many other things. You can use it to build polynomials, etc. I even used it in my VPI toolbox to perform multiplication of variable precision numbers. For example, suppose you want to multiply a pair of polynomials? I'll do it using syms first.
Suppose I want to multiply (x+1) by (x^2 - 3*x - 2)? Firt, in symbolic form so we can compare the results.
syms x
expand((x+1)*(x^2 - 3*x - 2))
But now recognize that these polynomials can be represented as a list of coefficients in standard MATLAB form.
conv([1,1],[1 -3 -2])
Do you see the multiplication worked perfectly? As a result, we now have a list of coefficients of the product polynomial. Try it with other products of polynomials, and it always works, at least as long as there are no problems with the precision of the coefficients in double precision arithmetic.
Why does it work? Think about what conv does. Expand it out, and you will see that convolution does exactly what you want with the product of those polynomials. (Conv is a tremendously valuable tool, useful in many areas of mathematics. I cannot begin to count the number of ways I have used it over the years.)
Accepted Answer
John D'Errico
on 17 Jan 2023
Edited: John D'Errico
on 17 Jan 2023
First, the two sets of polynomials are effectively the same thing, but for a transformation. As you said, the two are just orthogonal with respect to a subtly different version of the same exponential form. Here, for example, is the degree 3 polynomial, and that matches what wikipedia shows. First, note the normalization. These are not normalized to have the coefficient of the highest degree term 1.
syms x
P3 = hermiteH(3,x)
This is what Wikipedia refers to as a physicist's polynomials. They are orthognal wrt exp(-x^2). So effectively derived from an erf, which makes sense in context. For example...
P2 = hermiteH(2,x)
then we would expect to find this integral to be zero.
int(P2*P3*exp(-x^2),[-inf,inf])
Every once in a while something works. ;-) But not everything. I prefer my orthognal polynomials to be normalized to have unit norm too. And that would mean this next would yield 1. Such is life. Just a scale factor, and I can live with it.
int(P3*P3*exp(-x^2),[-inf,inf])
The Probabilists form will be orthogonal to exp(-x^2/2). We should recognize this from the Gaussian (Normal) distribution PDF. And we can get one from the other.
S2 = sqrt(sym(2));
hermiteH(3,x/S2)
But we need to normalize it, so the highest order term has coefficient 1, at least if you want to match the table. And to do that, you just divide by 2^(n/2), So I'll write a little function that does it:
hermiteProb = @(x,n) simplify(hermiteH(n,x/S2)/S2^n);
P2prob = hermiteProb(x,2)
P3prob = hermiteProb(x,3)
int(P2prob*P3prob*exp(-x^2/2),[-inf,inf])
Again, they are orthogonal wrt the indicated weight function. (WHEW! Got lucky again!) Though they are not normalized so the integral is 1, as would be expected if they were orthonormal. Oh well, I guess nothing is ever perfect. Still they have the form you desire.
int(P3*P3*exp(-x^2/2),[-inf,inf])
Still not my favorite normalization. Oh well.
Finally, if you want to evaluate these polynomials at a list of points, that is pretty easy. You could convert them to a function, using matlabFunction.
P3probfun = matlabFunction(P3prob)
P3probfun(-1.5:.5:1.5)
Or plot it.
X = linspace(-5,5);
plot(X,P3probfun(X),'-')
grid on
4 Comments
More Answers (0)
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!