Stavros Macrakis wrote:
> Why not use subst?
>
> On Thu, Sep 11, 2008 at 1:53 PM, Wolfgang Lindner
> <LindnerW at t-online.de <mailto:LindnerW at t-online.de>> wrote:
>
> dear list,
>
> is there a recommended way to do the composition of functions?
> Currently I do the following, but it becomes 'ugly' doing the
> composition of more than 2 functions:
>
> (%i93) comp(g,f,x):=limit(g,x,f); /* (g o f)(x) := g(f(x)) */
> (%i94) comp(sqrt(1-x^2),sqrt(x) ,x);
> (%o94) sqrt(1-x)
> (%i95) comp(asin(x),sin(x) ,x);
> (%o95) x
>
> Is it ok to use Maxima's limit function for that?
> What is your advice, please?
>
> Sincerely
> Wolfgang
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu <mailto:Maxima at math.utexas.edu>
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
Speaking of this, here is a simple routine which I developed some time
ago to do several 'subst' to get compositions of functions in several
variables. Is this type of thing already in maxima?
msubst(list,expr):=
block([lv: listofvars(expr), ft: expr], if length(lv)#length(list)
then print("Error: number of variables in",list,"must equal number of
variables in, expr") else
for i:1 thru length(lv) do ft: subst(lv[i]=list[i],ft),
return(ft))$
msubst_usg: print("msubst(list, expr) substitues the elements in the
list 'list' for the variables in expr. The length of 'list' must equal
the number of variables in 'expr' ");
An example:
(%i35) f: [x^3 + y, x^2 - y^2, x-y];
(%o35) [y+x^3,x^2-y^2,x-y]
(%i36) g: [u-v, u+v^2];
(%o36) [u-v,v^2+u]
(%i37) msubst(g,f);
(%o37) [v^2+(u-v)^3+u,(u-v)^2-(v^2+u)^2,-v^2-v]
-sen