我正在尝试使用fsolve函数在MATLAB中找到非线性系统的解决方案。我知道解决方案所在的区域,因此我的初始点是该区域内的随机变化。代码如下:
%MATLAB parameters
digits = 32;
format shortEng
%Initialization of solving process
min_norm = realmax;
options = optimoptions('fsolve', 'Algorithm', 'trust-region-dogleg',...
'Display', 'off', 'FunValCheck', 'on', 'Jacobian', 'on',...
'DerivativeCheck', 'on');
%Solving loop
while 1
%Refreshes seed after 100000 iterations
rng('shuffle');
for n=1:100000
%Initial points are randomly placed in solving region
x_0 = zeros(1, 3);
x_0(1) = 20*(10^-3)+ abs(3*(10^-3)*randn);
x_0(2) = abs(10^(-90) + 10^-89*randn);
x_0(3) = abs(10*randn);
%Solving
[x, fval] = fsolve(@fbnd, x_0, options);
norm_fval = norm(fval);
%If norm is minimum, result is displayed
if all(x > 0.0) && (norm_fval < min_norm)
iter_solu = x;
display(norm_fval);
display(iter_solu);
min_norm = norm_fval;
end
end
end
要优化的功能及其jacobian遵循:
function [F, J] = fbnd(x)
F(1) = x(1) - x(2)*(exp(7.56/(1.5*0.025))-1);
F(2) = x(1) - x(2)*(exp((x(3)*0.02)/(1.5*0.025))-1)-0.02;
F(3) = x(1) - x(2)*(exp((6.06+x(3)*0.018)/(1.5*0.025))-1)-0.018;
J = [[1.0, -3.5790482371355382991651020082214*10^87, 0.0];...
[1.0, 1.0-exp((8/15)*x(3)),-(8/15)*x(2)*exp((8/15)*x(3))];...
[1.0, 1.0-exp(0.48*x(3)+161.6), -0.48*x(2)*exp(0.48*x(3)+161.6)]];
end
当我打开DerivativeCheck时,我收到以下错误:
Objective function derivatives:
Maximum relative difference between user-supplied
and finite-difference derivatives = 1.
User-supplied derivative element (1,1): 1
Finite-difference derivative element (1,1): 0
由于某种原因,事情dF(1)/ dx(1)应该是零而不是1,当它显然是1.所以我继续将J(1,1)替换为0,并且现在我遇到了与J(3,1)相同的问题:
Objective function derivatives:
Maximum relative difference between user-supplied
and finite-difference derivatives = 1.
User-supplied derivative element (3,1): 1
Finite-difference derivative element (3,1): 0
因此,我将J(3,1)替换为0,它只捕获较小的精度错误。有没有解释为什么它认为J(1,1)和J(3,1)应该为零?这对我来说真的很奇怪。