利用牛顿下山法求解偏导等于0的式子,我自己把公式嫁接到网上找到的牛顿下山法代码中,但是MATLAB运行会提示“无法执行赋值,因为左侧和右侧的元素数目不同。”,左边是一个数字,右边也是一个数字,请问是哪里有问题呢
```c++
clear clc
d = [2000, 2000, 2000]; % 第i种运输方式的运输距离
s = [75, 900, 250]; % 第i种运输方式的运输速度
l = [0.02, 0, 0]; % 第i种运输方式的货损率
u = [0.64, 3.23, 2.81]; % 第i种运输方式的单位运价率
p = [0.7794, 0.8836, 0.985]; % 第i种运输方式的准点率
syms x
m=-(1-l).*p;
q=d./s;
g=u.*d;
V=m.*(q.*x+g);
h=diff(sum(log(exp(V./min(V))./sum(exp(V./min(V))))),x);%代换函数
disp(h)
x0=NW(h,1,100);%100为迭代最大次数
function result=NW(h,x,n)
f=matlabFunction(h);
f1=matlabFunction(diff(h));
X(1)=x;
i=2;
r=1;%下山因子
while 1
X(i)=X(i-1)-r*f(X(i-1))/f1(X(i-1));
if abs(f(X(i))) <1e-5 %牛顿法流程
result=X(i);
return;
end
if abs(f(X(i)))<abs(f(X(i-1))) %下山因子满足条件
r=1;
else %下山因子不满足条件,减半
r=r/2;
end
if i>n
result=X(i);
return;
end
i=i+1;
% disp(Alpha)
% disp(i)
end
end
```