数值积分勒让德多项式MATLAB

时间:2014-09-22 12:42:08

标签: matlab numerical-methods numerical-integration

勒让德多项式在MATLAB中作为向量实现,您还可以获得在特定点x处评估的所有关联勒让德多项式。因此,我不知道如何在积分中使用这些函数。我的问题是:

如何在Matlab中的第n个勒让德多项式上评估-1到1的(数值计算(!))积分?

编辑:当我收到的答案真的不是我想要的:我想在MATLAB中使用勒让德多项式的实现,因为其他建议可能非常不稳定。

2 个答案:

答案 0 :(得分:2)

n=3 % degree of Legendre polynomial
step=0.1 % integration step
trapz(legendre(n,-1:step:1)')*step

这应该做你想做的事情

答案 1 :(得分:1)

正如@thewaywewalk所提到的,你可以使用trapz进行数字整合。

度数n的勒让德多项式定义为:

enter image description here

因此您可以在Matlab中定义它们,如下所示:

sym x % You probably have to define x as being symbolic since you integrate as a function of x.
x = -1:0.1:1;

n = 1; Change according to the degree of the polynomial.

F = (x.^2)-1).^n;

Pol_n = (1./((2.^n).*factorial(n))).*diff(F,x,n) % n is the degree of the polynomial

然后使用trapz:

Output = trapz(x,Pol_n)

这应该让你去。