shenmufeng 发表于 2006-5-26 10:45

[求助]大家帮忙纠个错谢谢!!!

想求一个符号函数梯度的通用算法<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>&gt;&gt; clear all <BR>&gt;&gt; x=' <BR><BR>x = <BR><BR>   1 <BR>   2 <BR><BR>&gt;&gt; grad(f(x),x) <BR>??? Subscripted assignment dimension mismatch. <BR><BR>Error in ==&gt; grad at 8 <BR>    grad_f(1,j) = diff(f,x(j,1));   <BR>错在哪里呢

happy 发表于 2006-5-26 11:14

回复:(shenmufeng)[求助]大家帮忙纠个错谢谢!!!...

求导的变量不能是数组里的一个元素

shenmufeng 发表于 2006-5-26 11:30

该怎么改呀<BR>谢谢
页: [1]
查看完整版本: [求助]大家帮忙纠个错谢谢!!!