assignment, evaluation, and substitutions



According to the manual
<expr>, <arg_1>, ..., <arg_n>
cannot be used instead of
ev (<expr>, <arg_1>, ..., <arg_n>)
as part of another expression, such as function definitions, or blocks.
Therefore, the substitutions should be made using function ev, not its alias
form.
To avoid intermediate variables, you can just define the functions like that
(I have trimmed unnecessary spaces and parentheses to make it simpler):

VtrF(h,r1,r2):=1/3*%pi*h*(r1^2+r2^2+(r1^2*r2^2));
ratsimp(ev(VtrF(h,r1,r2),r1=p1/(2*%pi),r2=p2/(2*%pi)));
VtpF(h,p1,p2):=''%;

This would define VtrF(h,r1,r2) and VtpF(h,p1,p2) without using auxiliary
variables:
values;
--> [ ]

2011/10/12 Sebastian P. Luque <spluque at gmail.com>

> On Tue, 11 Oct 2011 11:26:46 -0500,
> "Sebastian P. Luque" <spluque at gmail.com> wrote:
>
> > Hi, I'm slowly learning these important topics in maxima by working
> > through a simple exercise in geometry.  Starting with the expression
> > for the volume of an object, based on 2 radii (r1, r2) and height (h):
>
> > Vtr: (1/3) * %pi * h * ((r1^2) + (r2^2) + ((r1^2) * (r2^2)));
>
> > So the expression has been assigned to the variable Vtr, and now I
> > want to find the expression where the radii are defined in terms of
> > the perimeter (p):
>
> > r: p / (2 * %pi);
>
> > How can this substitution be made efficiently, so as not to type this
> > for each radius?  If Vtr above and the perimeter-based equivalent are
> > needed as functions to call with different heights and
> > radii/perimeters, when should the function definitions (i.e. :=) be
> > made?  In other words, is it better to work with simple variable
> > assignments until after the substitutions are made?
>
> This is how I've done it:
>
> /* The volume of a truncated cone, using radii only */
> Vtr: (1/3) * %pi * h * ((r1^2) + (r2^2) + ((r1^2) * (r2^2)));
> /* Obtain the equivalent expression, substituting radii for perimeters */
> Vtr, r1=p1/(2 * %pi), r2=p2/(2 * %pi);
> /* Simplify expression and assign to a variable  */
> Vtp: ratsimp(%);
> /* Assign the expressions to functions for later use */
> VtrF(h, r1, r2) := ''Vtr;
> VtpF(h, p1, p2) := ''Vtp;
>
> but I'm left with the variables Vtr and Vtp.  Is there a better way to
> do this?  Thanks.
>
> --
> Seb
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>