From dc225672f0628abaf7dbd5eb1ab43d1f892dbcd8 Mon Sep 17 00:00:00 2001
From: Antoine Hoffmann <antoine.hoffmann@epfl.ch>
Date: Tue, 16 Apr 2024 13:04:23 +0200
Subject: [PATCH] add hermite polynomials computation and normalized

---
 matlab/compute/HermitePhys.m      | 40 +++++++++++++++++++++++++++++
 matlab/compute/HermitePhys_norm.m | 42 +++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 matlab/compute/HermitePhys.m
 create mode 100644 matlab/compute/HermitePhys_norm.m

diff --git a/matlab/compute/HermitePhys.m b/matlab/compute/HermitePhys.m
new file mode 100644
index 00000000..e5c0bc58
--- /dev/null
+++ b/matlab/compute/HermitePhys.m
@@ -0,0 +1,40 @@
+
+% HermitePoly.m by David Terr, Raytheon, 5-10-04
+
+% Given nonnegative integer n, compute the 
+% Hermite polynomial H_n. Return the result as a vector whose mth
+% element is the coefficient of x^(n+1-m).
+% polyval(HermitePoly(n),x) evaluates H_n(x).
+
+
+function hk = HermitePoly(n)
+% Evaluate the normalized Hermite polynomial.
+if n==0 
+    hk = 1;
+elseif n==1
+    hk = [2 0];
+else
+    
+    hkm2 = zeros(1,n+1);
+    hkm2(n+1) = 1;
+    hkm1 = zeros(1,n+1);
+    hkm1(n) = 2;
+
+    for k=2:n
+        
+        hk = zeros(1,n+1);
+
+        for e=n-k+1:2:n
+            hk(e) = 2*(hkm1(e+1) - (k-1)*hkm2(e));
+        end
+        
+        hk(n+1) = -2*(k-1)*hkm2(n+1);
+        
+        if k<n
+            hkm2 = hkm1;
+            hkm1 = hk;
+        end
+        
+    end
+    
+end
\ No newline at end of file
diff --git a/matlab/compute/HermitePhys_norm.m b/matlab/compute/HermitePhys_norm.m
new file mode 100644
index 00000000..eca67bb2
--- /dev/null
+++ b/matlab/compute/HermitePhys_norm.m
@@ -0,0 +1,42 @@
+% Normalized version of
+% HermitePoly.m by David Terr, Raytheon, 5-10-04
+
+% Given nonnegative integer n, compute the 
+% Hermite polynomial H_n. Return the result as a vector whose mth
+% element is the coefficient of x^(n+1-m).
+% polyval(HermitePoly(n),x) evaluates H_n(x).
+
+
+function hk = Hp(n)
+% Evaluate the normalized Hermite polynomial.
+if n==0 
+    hk = 1;
+elseif n==1
+    hk = [2 0];
+else
+    
+    hkm2 = zeros(1,n+1);
+    hkm2(n+1) = 1;
+    hkm1 = zeros(1,n+1);
+    hkm1(n) = 2;
+
+    for k=2:n
+        
+        hk = zeros(1,n+1);
+
+        for e=n-k+1:2:n
+            hk(e) = 2*(hkm1(e+1) - (k-1)*hkm2(e));
+        end
+        
+        hk(n+1) = -2*(k-1)*hkm2(n+1);
+        
+        if k<n
+            hkm2 = hkm1;
+            hkm1 = hk;
+        end
+        
+    end
+end
+% Normalization
+% hk = 1/sqrt(2^n*factorial(n))/sqrt(sqrt(pi))*hk;
+hk = 1/sqrt(2^n*factorial(n))/sqrt(sqrt(pi))*hk;
-- 
GitLab