Issue with lsqnonlin function solve

9 visualizaciones (últimos 30 días)
Andrzej Madej
Andrzej Madej el 11 de Abr. de 2021
Comentada: Walter Roberson el 13 de Abr. de 2021
Hello!
I am working with some algorithms to find optimal solution by changing 3 parameters.
The function I want to minimize to find optimal parameters is: where a,b,c are fixed values and x_1 to x_5 are my parameters, where a,b,s are fixed values and x_1 to x_5 are my parameters.
First I did example for one case - which works:
calibrator=@(x)(fix_value-f(a,b,c,x(1),x(2),x(3),x(4),x(5)))^2/sigma^2;
startparameters = [0.2 2 0.6 0.5 2 ];
options = optimset('Display','iter');
startparameters = [0.2 2 6 0.25 1 ];
calibrator=@(x)(fix_value-f(a,b,c,x(1),x(2),x(3),x(4),x(5),N))^2/sigma^2;
fminsearch(calibrator,startparameters, options)
Now I want to do the same for set of equations which are non linear. Now inputs are columns (fix_value, sigma) and function f returns column as well. I found function lsqnonlin as a way to solve my issue but id does not work:
calibrator=@(x)(fix_values-fs(a,b,c,x(1),x(2),x(3),x(4),x(5))).^2./sigmas.^2;
startparameters = [0.2 2 0.6 0.25 1];
options = optimoptions('lsqnonlin', 'Display', 'iter');
xopt = lsqnonlin(calibrator,startparameters, ...
[eps eps -1+eps eps eps ],
[Inf Inf 1-eps Inf Inf ]);
Error using lsqncommon (line 15)
Objective function is returning undefined values at initial point. lsqnonlin cannot continue.
Error in lsqnonlin (line 260)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,optimgetFlag,caller,...
Any idea how to handle this issue?

Respuestas (1)

Walter Roberson
Walter Roberson el 11 de Abr. de 2021
fix_values is a column. You subtract something from it (suppose it is a column as well), getting a column. Then you try to ^2 the column. However ^ is the Matrix Power operator, which can only be used with square matrices. You need to use .^2 instead.
Your sigma is also a column, you said, so you need sigma.^2
You would then have column / column which would be a matrix fitting operation. You need ./ instead of /
  3 comentarios
Walter Roberson
Walter Roberson el 12 de Abr. de 2021
FT_prob_dens is needed by heston_call
Walter Roberson
Walter Roberson el 13 de Abr. de 2021
You deleted the link to your github code and data, which makes it impossible for anyone else to have a look to see if they can see something I missed, or if they can make educated guesses about what the missing FT_prob_dens() function does and so potentially get further without waiting for you to make the code available.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by