Search code examples
maxima

maxima: use function as function argument


Like the title says, I want to use a function as a function argument. Intuitive I tried something like:

a(t,c) := t+c;
b(R_11, R_12, R_13, d_1x, d_1y, d_1z) := R_11*d_1x + R_12*d_1y + R_13*d_1z;

f( a(t,c), b(R_11, R_12, R_13, d_1x, d_1y, d_1z), %lambda ) := a(t,c) + 
     %lambda * b(R_11, R_12, R_13, d_1x, d_1y, d_1z);

But Maxima stated "define: in definition of f, found bad argument"

My goal is to simplify my equations to get a better overview. When I differentiate like

diff( f(...), R_11 )

the result for this example should be the partial derivative of b with respect to R_11.

f' = b_R11(...)

Is there a way to do such thinks or is this an odd attempt and there is maybe a better way?


Solution

  • You can declare that b depends on some arguments and then diff will construct formal derivatives of b.

    (%i1) depends (b, [R1, R2]);
    (%o1)                             [b(R1, R2)]
    (%i2) depends (a, t);
    (%o2)                               [a(t)]
    (%i3) f(t, R1, R2) := a(t) + b(R1, R2);
    (%o3)                  f(t, R1, R2) := a(t) + b(R1, R2)
    (%i4) diff (f(t, R1, R2), R1);
                                     d
    (%o4)                           --- (b(R1, R2))
                                    dR1
    (%i5) diff (f(t, R1, R2), t);
                                       d
    (%o5)                              -- (a(t))
                                       dt
    

    But that only works as long as b is undefined. When b is defined, diff will go ahead and call b and compute the derivative with respect to whatever is returned.

    (%i8) b(R1, R2) := 2*R1 + 3*R2;
    (%o8)                      b(R1, R2) := 2 R1 + 3 R2
    (%i9) diff (f(t, R1, R2), R1);
    (%o9)                                  2