complex function works only after defining it twice



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
redefine it.

-- 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:
makelist(reservoir[i],i,1,num_vars)

--   (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
defining functions

-- 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) ) $

     er(f,[a,b,c])

But keeping track of the arguments in the 'depends' system?

Hope this helps,

            -s