[求助]大家帮忙纠个错谢谢!!!
想求一个符号函数梯度的通用算法<BR><BR>function f_grad = grad(f,x) <BR><BR>dim=size(x); <BR>for j=1:dim <BR> grad_f(1,j) = diff(f,x(j,1)); <BR>end <BR>f_grad = grad_f.'; <BR><BR><BR>%%%%%%%%%%%%%%%%%%%%%%%%% <BR><BR>function A=f(x) <BR>A=100*(x(2)-x(1)^2)^2+(1-x(2))^2; <BR><BR><BR><BR>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <BR><BR>>> clear all <BR>>> x=' <BR><BR>x = <BR><BR> 1 <BR> 2 <BR><BR>>> grad(f(x),x) <BR>??? Subscripted assignment dimension mismatch. <BR><BR>Error in ==> grad at 8 <BR> grad_f(1,j) = diff(f,x(j,1)); <BR>错在哪里呢回复:(shenmufeng)[求助]大家帮忙纠个错谢谢!!!...
求导的变量不能是数组里的一个元素 该怎么改呀<BR>谢谢
页:
[1]