Fixing Value in lsqnonlin
Mostrar comentarios más antiguos
I have seen that based off the lsqnonlin algorithm, that the upper and lower bounds are not strictly respected for different iterations of lsqnonlin. I have a case where I am attempting to optimize a general N by N square array where some of the values should occassionally be fixed to 0. The issue is illustrated by the function used to optimize, shown below.
An example K can have the form [a, 0; b, c]. If I don't include the 0 in the optimization, the code runs with no problem. However, I would like to make this function general to any N by N array of K. The issue arrises when lsqnonlin changes the 0 to something like 1e-8 even though my upper and lower bounds are both 0, which in turn gets blown up as expm(1e8). Is there a good way to fix the value of the 0s?
Secondary question: I only inverted the K inside the optimzation function because the fit didn't work very well when I was optimizing the small decimal values. It seems that lsqnonlin thinks that a change of lets say 1/500 vs 1/600 is less significant than a change between 500 and 600. If this is something I can tune in the options that I have not discovered, I would happily optimize the non-inverted numbers.
Thanks!
function xout = Global_SAS_1(T,Y,K)
%if Y is n1 by n2, T needs to be size 1 x n2
%K can be an arbitrary matrix size. Will have units as T^-1.
Tm = zeros(numel(K),length(T));
Kinv = 1./K;
Kinv(isinf(Kinv)) = 0; % in matlab, 1/0 = inf
for i = 1:length(T)
A = expm(Kinv*T(i));
Tm(:,i) = A(:);
end
Gm = real(Y)*pinv(Tm);
xout = Gm*Tm - Y
5 comentarios
The issue arrises when lsqnonlin changes the 0 to something like 1e-8 even though my upper and lower bounds are both 0
How old is your Matlab version? In a recent version of Matlab, that really shouldn't happen. When you make one of the lb(i)=ub(i), both lsqnonlin and lsqcurvefit internally reformulate the problem so that x(i) is treated as a known variable. I recommend you post a full enough version of your code that we can run the optimization.
Matt J
el 27 de Ag. de 2019
Very kind of you, Adam!
Shawn Z
el 27 de Ag. de 2019
Note also this related thread,
You may have to explicitly reshape K to have the original NXN dimensions in your model function if you set one or more lb(i)=ub(i).
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Get Started with Optimization Toolbox en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!