[newbie] how to expand function to original variables



Hugo,

I strongly recommend you follow Rupert's second suggestion below (which is
the same as what Barton suggested some time ago).  Just because you call
something a 'function' doesn't mean that the best way to model it in Maxima
is as a Maxima 'function' (which you can also think of as a procedure, in
the programming-language sense).

The ''(...) and define mechanisms discussed below are useful for more
complicated cases, but you haven't shown us any reason that you'd need them.

           -s

On Tue, Feb 19, 2013 at 9:58 AM, Rupert Swarbrick <rswarbrick at gmail.com>wrote:

> Hugo Coolens <coolens at kahosl.be> writes:
> > I followed your advice and this is what I guess should be the right way?
> > p:tau11*tau22;
> > sigma:tau11+tau12+tau22;
> > A:sqrt(p^2+2*p*sigma)-p;
> > hjmax(A,sigma,p):=sqrt((1+A/p)/((1-A/sigma^2)^2+A/p));
> > ev(hjmax(A,sigma,p));
> >
> > Do you think this is OK?
>
> If you want to avoid having to do the "ev" bit at the end, you need to
> get the definition of hjmax to evaluate its right hand side. The :=
> operator doesn't do that by default (you can see this, since the result
> of defining hjmax will have p, sigma and A in it). You can either do
> something like
>
>   hjmax(A,sigma,p):=''(sqrt((1+A/p)/((1-A/sigma^2)^2+A/p)));
>
> or use define() as follows:
>
>   define (hjmax('A,'sigma,'p), sqrt((1+A/p)/((1-A/sigma^2)^2+A/p)));
>
> (note that I have to quote A, sigma and p here since define evaluates
> the argument list)
>
> OR
>
> You could choose not to define hjmax as a function. If you just wrote
>
>   hjmax : sqrt((1+A/p)/((1-A/sigma^2)^2+A/p));
>
> then you'd probably get exactly what you were after. To "evaluate" the
> result at a given set of taus, you could either do something like
>
>   hjmax, tau11 = 1, tau12 = 2, tau22 = 3;
>
> which is shorthand for a call to ev(), or use subst():
>
>   subst ([tau11 = 1, tau12 = 2, tau22 = 3], hjmax);
>
>
> Rupert
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>