There is a way in which the arguments of a function are optional, that is, that the following code will take only the first argument
Code : Tout sélectionner
def legendre_( n, evalX ):
local px, x; purge(x)
px := 1/(2^n*n!)*diff((x^2-1)^n,x,n)
if getType(evalX)=="NUM" or getType(evalX)=="EXPR" :
px:=subst(px,x=evalX)
elif getType(evalX)=="STR" and evalX=="poly1":
px:=e2r(px)
return px;
legendre_(2,""),legendre_(2,"poly1"),legendre_(2,10),legendre_(2,cos(t)) >
(3*x**2-1)/2, poly1[3/2,0,-1/2], 299/2, (3*cos(t)**2-1)/2