Сonvert the coefficients of the Hermite polynomial into a function

5 views (last 30 days)
Lizaveta Sauchanka
Lizaveta Sauchanka on 18 May 2022
Edited: Torsten on 18 May 2022
I want to make a function from the output of Matlab Hermite function (for example, if we had an output from Hermite function ```[8 0 -12 0]``` it would be ```8x^3 - 12x``` polynomial) and then integrate this function using the **Simpson's 3/8 Rule**.
I have already created a function in Matlab that integrate any function using this rule and also I have created function that returns coefficients of Hermite's polynomial (with the recursion relation) in the vector form.
My questions:
1) If it's possible, in Hermite function I want from this output ```[8 0 -12 0]``` make this output ```8x^3 - 12x```. This output I will able to integrate. How can I do this?
2) Can I combine these two functions and integrate Hermite's polynomial without convention the output of the first function?
Code of Hermite polynomial function, where n is the order of the polynomial:
```
function h = hermite_rec(n)
if( 0==n ), h = 1;
elseif( 1==n ), h = [2 0];
else
h1 = zeros(1,n+1);
h1(1:n) = 2*hermite_rec(n-1);
h2 = zeros(1,n+1);
h2(3:end) = 2*(n-1)*hermite_rec(n-2);
h = h1 - h2;
end
```
Code of Simpson function, that integrate function using the Simpson 3/8 Rule. a is a lower limit of integral, b is a upper limit of integral:
```function IS2 = NewtonIntegral(a,b)
n = 3;
h = (b-a)/(3*n); %3h = (b-a)/n
IS2=0;
for i=1:n
IS2 = IS2+(f(a+(3*i-3)*h) + 3*f(a+(3*i-2)*h) + 3*f(a+(3*i-1)*h) + f(a+(3*i)*h))*3*h/8;
end
end
```
Thank you for any advice!

Answers (1)

Torsten
Torsten on 18 May 2022
Edited: Torsten on 18 May 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by