From f35ea80659b6a49d1bb2ce1d7d002583f3f40947 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 10 Oct 2017 12:38:01 +0530 Subject: updated the code --- 75/CH5/EX5.7/ex_7.sce | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to '75/CH5/EX5.7/ex_7.sce') diff --git a/75/CH5/EX5.7/ex_7.sce b/75/CH5/EX5.7/ex_7.sce index a1608ff35..6eb53781d 100755 --- a/75/CH5/EX5.7/ex_7.sce +++ b/75/CH5/EX5.7/ex_7.sce @@ -1,3 +1,32 @@ +function [pL] = legendrepol(n,var) + +// Generates the Legendre polynomial +// of order n in variable var + +if n == 0 then + cc = [1]; +elseif n == 1 then + cc = [0 1]; +else + if modulo(n,2) == 0 then + M = n/2 + else + M = (n-1)/2 + end; + + cc = zeros(1,M+1); + for m = 0:M + k = n-2*m; + cc(k+1)=... + (-1)^m*gamma(2*n-2*m+1)/(2^n*gamma(m+1)*gamma(n-m+1)*gamma(n-2*m+1)); + end; +end; + +pL = poly(cc,var,'coeff'); +endfunction + +// End function legendrepol + // PG (277) deff('[y]=f(x)','y=exp(x)*cos(x)') -- cgit