[Maxima] complex function works only after defining it twice
macrakis at alum.mit.edu
Thu May 15 17:28:05 CDT 2008
Thanks for your interest in Maxima.
Here are some observations on your code.
-- As Barton observes, "error" is a built-in function; you shouldn't
-- The ''(...) construction is evaluated at the time your function is
*defined*, not at the time it is executed, so the ''diff's at the end
can't possibly be doing the right thing (this is probably related to
your second-time-around problem). In fact, all the '' 's seem to be
unnecessary -- the whole point of "define" is that both the first and
the second arguments are evaluated, so you could perfectly well do
define( funmake(pt,vars), diff( ... ) ).
-- The functions you are defining (pt, tempfunc, etc.) will be defined
*globally*. Is that what you want?
-- the cons(reservoir[i]...) loop can more simply be written as dvars:
-- (for j:1 thru length(dep[i]) do (vars: cons(part(dep[i], j),
vars)))), reverse(...) can be more simply written as vars:args(dep[i])
-- (for i:1 step 1 while i<=N ...) can be more simply written as (for
i thru N...)
-- I think you really should be operating on expressions rather than
-- I'm not quite sure what you're trying to do but is it something like this?:
er(f,args) := xreduce("+", makelist( abs(diff(f,a)) * del(a) , a, args) ) $
But keeping track of the arguments in the 'depends' system?
Hope this helps,
More information about the Maxima