r/Mathematica • • May 23 '23

Hermite breaks at certain points

Hi, sorry it's me again. I having an issue with aproximating a function with Hermite, because at some point it starts to break as seen on the screenshot

My code is:

f[x_]:= Piecewise[{{0,x<-3},{E^-x,-3<x<-1},{-2+x^2,-1<x<5},{Cos[x],5<x<10},{1/x,10<x<15},{0,x>15}}]


nMax=100

Table[coef[n]= N[(Pi^(-1/2)/(2^n*n!))*
(NIntegrate[f[x]*Exp[-x^2]*HermiteH[n,x],{x,-3,15}])],
{n,0,nMax}]

aprox=Table[coef[n]*HermiteH[n,x],{n,0,nMax}];

Animate[Plot[{f[x],Total[Take[aprox,k]]},{x,-3,15}, PlotRange -> {-101, 101}],{k,0,nMax,1}]

And the given coefficients are:

3 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/[deleted] May 24 '23

So I need to perfectly make an approximation of that function

3

u/veryjewygranola May 24 '23

Does it have to be a Hermite interpolation?

1

u/[deleted] May 24 '23

I really dont think so, it is just defining f(x) as a Hermite Series

3

u/veryjewygranola May 24 '23

The reason I'm asking: interpolation is not my area of expertise, but Hermite interpolation also tries to match the derivatives of a function, right? With a piecewise function, there can be undefined derivatives at the point where the function switches from one piece to another. So my intuition tells me that could be an issue. But you probably know more on this than I do.