简体   繁体   English

将 Hermite 多项式的系数转换为函数

[英]Сonvert the coefficients of the Hermite polynomial into a function

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 .我想从 Matlab Hermite 函数的输出中创建一个函数(例如,如果我们有 Hermite 函数[8 0 -12 0]的输出,它将是8x^3 - 12x多项式),然后使用Simpson's集成该函数3/8 规则

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.我已经在 Matlab 中创建了一个函数,该函数使用此规则集成任何函数,并且我还创建了以向量形式返回 Hermite 多项式(具有递归关系)的系数的函数。

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 .如果可能的话,在 Hermite 函数中,我想从此输出[8 0 -12 0]将此输出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?我可以结合这两个函数并整合 Hermite 的多项式而不约定第一个函数的输出吗?

Code of Hermite polynomial function, where n is the order of the polynomial: Hermite 多项式函数的代码,其中 n 是多项式的阶数:

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.辛普森函数代码,使用辛普森 3/8 规则集成函数。 a is a lower limit of integral, b is a upper limit of integral: 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!感谢您的任何建议!

To create a polynomial function given its coefficients, you can use polyval (see also anonynmous functions ):要在给定系数的情况下创建多项式函数,可以使用polyval (另请参见匿名函数):

p = [1 2]; % example. This represents the polynomial x+2
f = @(x) polyval(p, x); % anonymous function of x, assigned to function handle f

Now f is a function that you can integrate numerically.现在f是一个可以数值积分的函数。

If you want to include this directly as part of your Hermite function, just add something like this at the end:如果您想直接将其作为Hermite函数的一部分包含在内,只需在末尾添加如下内容:

h = @(x) polyval(p, x);

Then the Hermite function will return a function (handle) representing the Hermite polynomial.然后Hermite函数将返回一个表示 Hermite 多项式的函数(句柄)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM