The basic problem here is that Maxima in effect evaluates your expression
"f(t)" twice: once when creating the "explicit" expression, and once at
each value. This is in order to allow things like:
myexpr: sin(x)$
explicit(myexpr,x,0,6) <<< note that myexpr evaluates to sin(x),
then sin(x) evaluates to (e.g.) 0.0 for x=0.0
There are several possible ways of handling this:
1) Remove the calls to "return" in your function definition. This will
make it a pure expression (mathematical object) rather than executable
code. Then you can also get rid of the block:
f(t) := if 1<t and t<=2 then t-1 ...
Now f(x) (a symbolic argument) returns an expression with 'x' substituted
for 't': if 1<x and x<=2 then x-1 ...
2) Quote the function call when graphing it, e.g. '(f(t))
3) Use the function name instead of a function call, e.g.
explicit(f,xxx,0,5) (the variable xxx can be anything here)
I would recommend doing both (1) and (2) -- (1) because it makes your code
cleaner, and (2) because it's good to be clear about what you want
evaluated.
-s
On Mon, Aug 13, 2012 at 10:36 AM, Jorge Calvo <Jorge.Calvo at avemaria.edu>wrote:
> Hello there:
>
> I am trying to define some simple piecewise-linear functions that I can
> then plot. For instance,
>
> (%i01) f(t) := block(
> if 1 < t and t <= 2 then
> return(t-1)
> elseif 2 < t and t < 3 then
> return(3-t)
> else
> return(0))
> $
>
> By itself, this evaluates fine, but I cannot get Maxima to graph it. For
> instance, I run into trouble when I try:
>
> (%i02) draw2d(explicit(f(t), t, 0, 5));
>
> If graphing is my goal, should I be defining f in a different way?
>
> Thanks!
>
> Jorge
> --
> Dr. Jorge Alberto Calvo
> Associate Professor of Mathematics
> Department of Mathematics and Physics
> Ave Maria University
>
> Phone: (239) 280-1608
> Email: jorge.calvo at avemaria.edu
> Web: http://sites.google.com/site/jorgealbertocalvo
>
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>