[newbie] how to expand function to original variables



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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20130219/096d51c2/attachment.pgp>;