Sponsored links: Algebra eBooks
 

Related

tab

Run Example
(%i1)lagrange(tab) := block([n:length(tab),sum:0,prod],   for i:1 thru n do(      prod: 1,      for k:1 thru n do         if k#i then prod: prod * ('x-tab[k][1]) / (tab[i][1]-tab[k][1]),      sum: sum + prod * tab[i][2] ),   ratsimp(sum) );
(%o1) lagrange(tab) := block([n : length(tab), sum : 0, product], 
for i thru n do (product : 1, for k thru n 
                           product ('x - (tab ) )
                                             k
                                               1
do if k # i then product : ----------------------, 
                             (tab )  - (tab )
                                 i         k
                                   1         1
sum : sum + product (tab ) ), ratsimp(sum))
                        i
                          2
(%i2) lagrange([[1,1],[2,4],[3,9],[4,4],[5,1]]);
                         4       3       2
(%o2)                   x  - 12 x  + 48 x  - 72 x + 36
(%i3) lagrange([[1,-1],[2,-8],[3,18],[4,8],[5,1]]);
                        4        3        2
                     9 x  - 113 x  + 486 x  - 816 x + 432
(%o3)                ------------------------------------
                                      2
(%i4) lagrange([[1,1],[2,4],[3,9],[4,4],[5,1]]);
                         4       3       2
(%o4)                   x  - 12 x  + 48 x  - 72 x + 36
(%i5) lagrange([[1,1],[2,4],[3,9],[4,4],[5,1]]);
                         4       3       2
(%o5)                   x  - 12 x  + 48 x  - 72 x + 36
(%i6) 
Run Example
lagrange(tab) := block([n:length(tab),sum:0,prod],   for i:1 thru n do(      prod: 1,      for k:1 thru n do         if k#i then prod: prod * ('x-tab[k][1]) / (tab[i][1]-tab[k][1]),      sum: sum + prod * tab[i][2] ),   ratsimp(sum) );
(%o1) lagrange(tab) := block([n : length(tab), sum : 0, product], 
for i thru n do (product : 1, for k thru n 
                           product ('x - (tab ) )
                                             k
                                               1
do if k # i then product : ----------------------, 
                             (tab )  - (tab )
                                 i         k
                                   1         1
sum : sum + product (tab ) ), ratsimp(sum))
                        i
                          2
(%i2) lagrange([[1,1],[2,4],[3,9],[4,4],[5,1]]);
                         4       3       2
(%o2)                   x  - 12 x  + 48 x  - 72 x + 36
(%i3) lagrange([[1,-1],[2,-8],[3,-27],[4,8],[5,1]]);
                         4        3         2
                     27 x  - 314 x  + 1233 x  - 1878 x + 936
(%o3)              - ---------------------------------------
                                        4
(%i4) lagrange([[1,1],[2,4],[3,9],[4,4],[5,1]]);
                         4       3       2
(%o4)                   x  - 12 x  + 48 x  - 72 x + 36
(%i5) lagrange([[1,1],[2,4],[3,9],[4,4],[5,1]]);
                         4       3       2
(%o5)                   x  - 12 x  + 48 x  - 72 x + 36
(%i6) 
Run Example
lagrange(tab) := block([n:length(tab),sum:0,prod],   for i:1 thru n do(      prod: 1,      for k:1 thru n do         if k#i then prod: prod * ('x-tab[k][1]) / (tab[i][1]-tab[k][1]),      sum: sum + prod * tab[i][2] ),   ratsimp(sum) );
(%o1) lagrange(tab) := block([n : length(tab), sum : 0, product], 
for i thru n do (product : 1, for k thru n 
                           product ('x - (tab ) )
                                             k
                                               1
do if k # i then product : ----------------------, 
                             (tab )  - (tab )
                                 i         k
                                   1         1
sum : sum + product (tab ) ), ratsimp(sum))
                        i
                          2
(%i2) lagrange([[1,8],[2,6],[3,3],[4,1],[5,8],[6,18]]);
                     5       4        3        2
                  2 x  - 33 x  + 196 x  - 525 x  + 660 x - 396
(%o2)           - --------------------------------------------
                                       12
(%i3) 

Related Help

Help for Tab