|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
想求一个符号函数梯度的通用算法<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=[1 2]' <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>错在哪里呢 |
|