From: Davide Sanseverinati on 19 May 2010 05:33 hi i have to evaluate the Hessian matrix for my Simulink model. I wrote my cost function in such a way that parameters of my Simulink model and NOT the states are the indipendents variables. At the purpose i wrote function costf = aircraft_costf(parameters) % my cost function assignin('caller','CL0',parameters(1)); assignin('caller','CLa',parameters(2)); assignin('caller','CLq',parameters(3)); % in these parts i change. from nominal value, assignin('caller','CD0',parameters(5)); % the value of the parameters in the % workspace [T,X,Y] = sim('My_non_linear_simulink_model'); % here i make % simulation of the model with those % parameters costf = Y(end,:); % here the mean square value of the difference from simulation % with nominal parameter and simulation with different parameter % is returned end then i call fminunc to get the hessian. i give it a value of parameters near to the nominal one [X1,FVAL,EXITFLAG,OUT,GRAD,HESSIAN]=fminunc(@aircraft_costf,parameters,OPT) then i have these message: "Optimization terminated at the initial point: the relative magnitude of the gradient at x0 less than options.TolFun." (this WHATEVER initial parameter i give it) "Computing finite-difference Hessian using user-supplied objective function". (after a while it return GRAD and HESSIAN , by they are ALL zero). It seems like that during evaluation of the algoritm, parameters remais unchanged anyway, such that the gradient turns out to be zero at the first evaluation whoever has the patience to give an advice to fix these problem wil have my eternal gratitude :) Davide
From: Steven Lord on 19 May 2010 09:39 "Davide Sanseverinati" <john.doe.nospam(a)mathworks.com> wrote in message news:ht0b8g$jr8$1(a)fred.mathworks.com... > hi > > i have to evaluate the Hessian matrix for my Simulink model. I wrote my > cost function in such a way that parameters of my Simulink model and NOT > the states are the indipendents variables. At the purpose i wrote > function costf = aircraft_costf(parameters) % my cost function > > assignin('caller','CL0',parameters(1)); > assignin('caller','CLa',parameters(2)); > assignin('caller','CLq',parameters(3)); % in these parts i change. from > nominal value, assignin('caller','CD0',parameters(5)); % the value of > the parameters in the % workspace Why change variables in the caller function's workspace? Use SIMSET to change the SrcWorkspace option instead. That way you don't risk "clobbering" any variables that may be named CL0, CLa, CLq, and CD0 in the workspace of the calling function (which will likely be FMINUNC or one of its helper functions.) And are you really doing nothing with parameters(4)? If so, why is your parameters vector 5 elements long? -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Davide Sanseverinati on 19 May 2010 12:19 Thank a lot!!!
|
Pages: 1 Prev: call output in function Next: Displaying multiple dicom images in gui |