Question: Would like help with op/nops in a function

Hi. I wrote a command for finding second derivative.

#secondderiv test of f(x,y)
f:=x^2+2*x*y+2*y^3:
Gradient(f,[x,y]);
soln:=solve(Equate(Gradient(f,[x,y]),<0,0>));
H:=hessian(f,[x,y]);
seq([subs(soln[k],eval(H)),det(subs(soln[k],eval(H)))],k=1..nops(op(soln)))

Everything runs fine ... except if I change the function f to
f:=x^2+2*x*y+2*y^2
Then I get error :
Error, invalid input: nops expects 1 argument, but received 2

I sort of understand the error, when there is a single solution
{x=0,y=0} , then the op removes the parentheses to get x=0, y=0
which is now two arguments, and nops requires one argument.
I tried to use  nops(op({soln} ) , but that is not the correct approach
since it overcounts. Also it throws an error if change back f to the original expression.


 

 

Please Wait...