Numerical integration Legendre Polynomials MATLAB

只愿长相守 提交于 2019-12-13 04:16:09

问题


The Legendre polynomials are implemented in MATLAB as vectors, where you also get all the associated Legendre polynomials evaluated at a particular point x. Thus, I don't know how I can use these functions inside an integral. My question is:

How can I evaluate the (NUMERICALLY CALCUALTED(!)) integral from -1 to 1 over the n-th Legendre polynomial in Matlab?

EDIT: As I received an answer that is really not what I want: I want to use the implementation of the Legendre polynomials in MATLAB cause other suggestions may be highly unstable.


回答1:


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

this should do what you want




回答2:


As @thewaywewalk mentionned, you can use trapz to numerically integrate.

Legendre polynomials of degree n are defined as:

Therefore you can define them in Matlab like so:

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

Then using trapz :

Output = trapz(x,Pol_n)

That should get you going.



来源:https://stackoverflow.com/questions/25974427/numerical-integration-legendre-polynomials-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!