> fr2=function(x){
+   x1=x[1]
+   x2=x[2]
+   x3=x[3]
+   (x1^2+x2-x3)^2+(x1+x2^2-x3)^2
+ }
> grr=function(x){
+   x1=x[1]
+   x2=x[2]
+   x3=x[3]
+   c(2*x1*2*(x1^2+x2-x3)+2*(x1+x2^2-x3),
+     2*(x1^2+x2-x3)+2*x2*2*(x1+x2^2-x3),
+     -2*(x1^2+x2-x3)-2(x1+x2^2-x3))
+ }
> uimat=rbind(c(1,0,0),c(0,1,0),c(0,0,1))
> cimat=c(0,0,0)
> cop=constrOptim(c(0.1,0.2,0.3),fr2,grr,ui=uimat,ci=cimat)
Error in grad(theta, ...) : attempt to apply non-function
后面这个报错,是什么问题,怎么修改?求大神解答,谢谢!