help-octave
[Top][All Lists]

## Re: normalized ALF (Assotiated Legendre Function)

 From: Ben Abbott Subject: Re: normalized ALF (Assotiated Legendre Function) Date: Tue, 12 Feb 2008 08:29:59 -0500

```
On Feb 12, 2008, at 3:06 AM, Marco Caliari wrote:

```
```I compared Matlab's script and Octave's and your proposal.

result_matlab = legendre (80, [-1:0.1:1]);

```
result_octave0 respects the original and result_octave1 respects your algorithm.
```
```
I calculated an error with respect to the matlab version (I'm not sure Matlab's is to be trusted as correct in all cases).
```
d0 = abs (result_matlab - result_octave0) / abs (result_matlab);
d1 = abs (result_matlab - result_octave1) / abs (result_matlab);
er1 = max (d1, [], 2);
er0 = max (d0, [], 2);

[er0(:), er1(:)] produces the following
```
```
Dear Ben,

```
the results are even more impressive if you consider that legendre0(80,[-1:0.1:1])(1,1) gives 6.7015e+14, whereas legendre1(80, [-1:0.1:1])(1,1) gives 1.
```
```
I'm inclined to agree that the recursion form should work better. I'm suspicious that Matlab's version is reliable for such high order legendre polynomials.
```
Anyone, is there a reliable method to verify the correct answers?
```
```
```
There is a LegendreP function in Maple doing exactly the same. Can you select few cases (a degree and a scalar value for x) for which the difference between Matlab and my script is quite large? I will check them with Maple.
```
```
I haven't used Maple in several years. Is it not possible to evaluate the example, legendre (80, [-1:0.1:1]), and post the results (as an attachment)?
```
It can then read it as ...

```
and compared directly to octave and Matlab. I realize that we'll loose some precision, but if 16 digits are preserved, we should obtain relative errors on the order 10^(-15).
```
```
I notice Maxima also has a legendre function, legendre_p(n,m,x). Which uses `Abramowitz and Stegun, Handbook of Mathematical Functions' as the reference. I'll take a look at calculating the example there.
```
Ben

```