UNPKG

1.44 kBtext/coffeescriptView Raw
1###
2 Laguerre function
3
4Example
5
6 laguerre(x,3)
7
8Result
9
10 1 3 3 2
11 - --- x + --- x - 3 x + 1
12 6 2
13
14The computation uses the following recurrence relation.
15
16 L(x,0,k) = 1
17
18 L(x,1,k) = -x + k + 1
19
20 n*L(x,n,k) = (2*(n-1)+1-x+k)*L(x,n-1,k) - (n-1+k)*L(x,n-2,k)
21
22In the "for" loop i = n-1 so the recurrence relation becomes
23
24 (i+1)*L(x,n,k) = (2*i+1-x+k)*L(x,n-1,k) - (i+k)*L(x,n-2,k)
25###
26
27
28
29Eval_laguerre = ->
30 # 1st arg
31
32 push(cadr(p1))
33 Eval()
34
35 # 2nd arg
36
37 push(caddr(p1))
38 Eval()
39
40 # 3rd arg
41
42 push(cadddr(p1))
43 Eval()
44
45 p2 = pop()
46 if (p2 == symbol(NIL))
47 push_integer(0)
48 else
49 push(p2)
50
51 laguerre()
52
53#define X p1
54#define N p2
55#define K p3
56#define Y p4
57#define Y0 p5
58#define Y1 p6
59
60laguerre = ->
61 n = 0
62 save()
63
64 p3 = pop()
65 p2 = pop()
66 p1 = pop()
67
68 push(p2)
69 n = pop_integer()
70
71 if (n < 0 || isNaN(n))
72 push_symbol(LAGUERRE)
73 push(p1)
74 push(p2)
75 push(p3)
76 list(4)
77 restore()
78 return
79
80 if (issymbol(p1))
81 laguerre2(n)
82 else
83 p4 = p1; # do this when p1 is an expr
84 p1 = symbol(SECRETX)
85 laguerre2(n)
86 p1 = p4
87 push(symbol(SECRETX))
88 push(p1)
89 subst()
90 Eval()
91
92 restore()
93
94laguerre2 = (n) ->
95 i = 0
96
97 push_integer(1)
98 push_integer(0)
99
100 p6 = pop()
101
102 for i in [0...n]
103
104 p5 = p6
105
106 p6 = pop()
107
108 push_integer(2 * i + 1)
109 push(p1)
110 subtract()
111 push(p3)
112 add()
113 push(p6)
114 multiply()
115
116 push_integer(i)
117 push(p3)
118 add()
119 push(p5)
120 multiply()
121
122 subtract()
123
124 push_integer(i + 1)
125 divide()
126
127