Creating a function?



I've been working a little with Michel Talon on enhancing colnew.  One
of the steps is defining a function to return each row of the Jacobian
of the boundary conditions.

In Michel's example, the boundary conditions are expressed as the
vector function

g(z) := [z[2] - 2.0d0*z[1]*(v-z[3]-z[4]), z[2] - 2.0d0*z[1]*z[3],
                z[1] - 1.0d0, z[2] - 2.0d0*z[1]*z[4]]; 

The function we want is then

dg:jacobian(g(z), [z[1],z[2],z[3],z[4]]);
dgsub(i, z) := row(dg, i)[1];

However dgsub doesn't work as we need:

dgsub(1, w) -> [-2.0*(-z[4]-z[3]+0.1),1,2.0*z[1],2.0*z[1]]

What is the correct way to define the function dgsub?  

I did find that the following definition does what we need:

dgsub(i,z) := ev(row(dg, i)[1]);

dgsub(1,w) -> [-2.0*(-w[4]-w[3]+0.1),1,2.0*w[1],2.0*w[1]]$

dgsub(1,[1,2,3,4]) -> [13.8, 1, 2.0, 2.0]


Ray