matlab求高次埃尔米特多项式,MATLAB中Hermite多项式的可视化

本文介绍了一个用于计算Hermite多项式的Matlab函数。该函数支持递归生成指定阶数的Hermite多项式,并能返回一系列多项式。文章通过实例展示了如何使用此函数来生成多项式并进行绘图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

function h=hermite( n, all_polys )

% HERMITE  Return the n-th Hermite polynomial.

%   H=HERMITE(N) with n integer and non-negative returns the n-th

%   (probabilistic) Hermite polynomial H_i(x). The returned polynomials is

%   not normalized so that =i! delta_ij, where <.> denotes the

%   expected value with respect to the Gauss measure exp(-x^2/2)/sqrt(2*pi).

%   The algoritm uses the three term recurrence

%      $$H_{n+1}(x) = x H_n - n H_{n-1}$$

%   with H_0=1 and H_1=x. The returned polynomial uses the standard matlab

%   representation of polynomials where the first element corresponds to the

%   highest power of x and the last element to the constant. E.g.

%   hermite(4) returns [1,0,-6,0,3] which means x^4-6*x^2+3. Polynomials of

%   this kind can be easily manipulated and evaluated in Matlab using the

%   functions polyint (integration), polyder (derivatives), conv

%   (multiplication) and polyval (evaluation).

%%   H=HERMITE(N,TRUE) returns all Hermite polynomials up to degree N.

%% Example (run)

%   h1=hermite( 1 ); format_poly( h1 );%   h2=hermite( 2 ); format_poly( h2 );

%   h3=hermite( 3 ); format_poly( h3 );%   h4=hermite( 4 ); format_poly( h4 );

%   x=linspace(-1,1);%   plot(x,polyval(h1,x),x,polyval(h2,x),x,polyval(h3,x),x,polyval(h4,x));

%% See also HERMITE_VAL, FORMAT_POLY%   Elmar Zander%   Copyright 2006, Institute of Scientific Computing, TU Braunschweig.

%%   This program is free software: you can redistribute it and/or modify it

%   under the terms of the GNU General Public License as published by the

%   Free Software Foundation, either version 3 of the License, or (at your

%   option) any later version.%   See the GNU General Public License for more details. You should have

if n==0

h=1;

return;

end

if nargin<2 || ~all_polys

% Compute just a single polynomial of degree n

p=1;

q=[1 0];

for i=1:n-1;

% The following code line implements the Hermite recurrence        % relation

%   H_{n+1} = x H_n(x) - n H_{n-1}

[q,p]=deal([q 0]-i*[0 0 p],q);

end

h=q;

else

% Compute all polynomials up to degree n

h=zeros(n+1,n+1);

% H_0 = 1

h(1,end)=1;

% H_1 = x

h(2,end-1)=1;

for i=2:n

% The following code line implements the Hermite recurrence

% relation

%   H_{n+1} = x H_n(x) - n H_{n-1}

h(i+1,:)=[h(i,2:end) 0]-(i-1)*h(i-1,:);

end

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值