# [Scilab-users] Least squares problem call to fmincon - HELP

5 messages
Open this post in threaded view
|

## [Scilab-users] Least squares problem call to fmincon - HELP

 How may i (if possible?) reconfigure the least-squares problem to be solved with a minimalist call to fmincon (from the fossee toolbox)? I tried everything, but must be (seriously?) overlooking something! Perhaps something like: function z=fun(p)         z=DAT(:,2)-p(1)*exp(p(2)*DAT(:,1))-p(3)*ones(DAT(:,1)) endfunction function dz=dfun(p)         var=exp(p(2)*DAT(:,1))         dz=[-var..         -p(1)*DAT(:,1).*var..         -ones(var)] endfunction //function [f,g,ind]=costf(p,ind) // f=fun(p); g=dfun(p) //endfunction function [f,g,ind]=costf(p,ind)         f=norm(fun(p))^2; // g=2*dfun(p)'*fun(p);         g=2*numderivative(fun,p)'*fun(p); endfunction DAT=[0 0;0 1;1 1;2 1.5;2 2]; p0=[0 0 0]; A=[]; b=[]; [popt,fopt]=fmincon(costf,p0,A,b); disp(popt,'popt',fopt,'fopt'); fmincon.sce   Dave -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Least squares problem call to fmincon - HELP

 Le 09/01/2020 à 22:32, David Brant a écrit : ```How may i (if possible?) reconfigure the least-squares problem to be solved with a minimalist call to fmincon (from the fossee toolbox)? I tried everything, but must be (seriously?) overlooking something! Perhaps something like: function z=fun(p) z=DAT(:,2)-p(1)*exp(p(2)*DAT(:,1))-p(3)*ones(DAT(:,1)) endfunction function dz=dfun(p) var=exp(p(2)*DAT(:,1)) dz=[-var.. -p(1)*DAT(:,1).*var.. -ones(var)] endfunction //function [f,g,ind]=costf(p,ind) // f=fun(p); g=dfun(p) //endfunction function [f,g,ind]=costf(p,ind) f=norm(fun(p))^2; // g=2*dfun(p)'*fun(p); g=2*numderivative(fun,p)'*fun(p); endfunction DAT=[0 0;0 1;1 1;2 1.5;2 2]; p0=[0 0 0]; A=[]; b=[]; [popt,fopt]=fmincon(costf,p0,A,b); disp(popt,'popt',fopt,'fopt'); fmincon.sce Dave``` By default, fmincon expects costf to return only the objective function. Hence you should define it like this ```function f=costf(p) f = norm(fun(p))^2; endfunction``` There is a way to provide the exact gradient of f, as described here: https://scilab.in/fossee-scilab-toolbox/optimization-toolbox/functions/fmincon ```function g = grad(p) g = 2*dfun(p)'*fun(p); endfunction``` ```options = list("GradObj",grad) xopt = fmincon(f,x0,A,b,[],[],[],[],[],options)``` S. ``` -- Sent from: https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html _______________________________________________ users mailing list [hidden email] https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users ``` ```-- Stéphane Mottelet Ingénieur de recherche EA 4297 Transformations Intégrées de la Matière Renouvelable Département Génie des Procédés Industriels Sorbonne Universités - Université de Technologie de Compiègne CS 60319, 60203 Compiègne cedex Tel : +33(0)344234688 http://www.utc.fr/~mottelet ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|