Subject: assignment, evaluation, and substitutions
From: Sebastian P. Luque
Date: Tue, 11 Oct 2011 18:45:34 -0500
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