Model Browser User's Guide | ![]() ![]() |
Optional Subfunctions
function [LB,UB,A,c,nlcon,optparams]=i_constraints(U,b,varargin) LB=[0 0 0 0]'; UB=[1e10 1e10 1e10 1e10]'; A= [-1 1 0 0]; c= [0]; nlcon= 0; optparams= [];
Lower and upper bounds are stated for the model parameters. These are in the same order that the parameters are declared and used throughout the template file.
A linear constraint is defined:
b = the vector of model parameters, then the constraint is A*b <c We define A and c in the subfunction above
The number of nonlinear constraints is declared to be zero. If the number of nonlinear constraints is not zero, the nonlinear constraints are calculated in i_nlconstraints
.
No optional parameters are declared for the cost function.
The fit options are always based on the input fopts
. See MATLAB help on the function optimset
for more information on fit options. When there are no constraints the fitting is done using the MATLAB function lsqnonlin
, otherwise fmincon
is used.
function J= i_jacobian(U,b,x) x = x(:); J= zeros(length(x),4); a=b(1); beta=b(2); k=b(3); d=b(4); ekd= exp(-(k.*x).^d); j2= (a-beta).*(k.*x).^d.*ekd; J(:,1)= 1-ekd; J(:,2)= ekd; J(:,3)= j2.*d./k; J(:,4)= j2.*log(k.*x);
To speed up the fitting algorithm an analytic Jacobian can be supplied, as it is here.
These labels are used on plots and so on. Latex notation can be used and is formatted.
function str= i_char(U,b,fopts) s= get(U,'symbol'); str=sprintf('%.3g - (%.3g-%.3g)*exp(-(%.3g*x)^{%.3g})',... b([1 1 2 3 4]));
This is the display equation string and can contain Latex expressions. The current values of model parameters appear.
function str= i_str_func(U,b) s= get(U,'symbol'); lab= labels(U); str= sprintf('%s - (%s - %s)*exp(-(%s*x)^{%s})',... lab{1},lab{1},lab{2},lab{3},lab{4});
This displays the function definition with labels appearing in place of the parameters (not numerical values).
This does not need to be defined (can return an empty array). Here we define a response feature that is not one of the parameters (here it is also nonlinear).
function [rf,dG]= i_rfvals(U,b) % response feature definition rf= (1/b(3))*((b(4)-1)/b(4))^(1/b(4)) if nargout>1 % delrf/delbi dG= [0, 0, -((b(4)-1)/b(4))^(1/b(4))/b(3)^2,... 1/b(3)*((b(4)-1)/b(4))^(1/b(4))*... (-1/b(4)^2*log((b(4)-1)/b(4))+(1/b(4)-... (b(4)-1)/b(4)^2)/(b(4)-1))]; end
The response feature (labeled as INFLEX
above) is defined. The Jacobian is also defined here as dG
.
function p= i_reconstruct(U,b,Yrf,dG,rfuser) p= Yrf/dG'; f= find(rfuser>size(p,2)); if any(rfuser==4) % need to use delta p(:,3)= ((p(:,4)-1)./p(:,4)).^(1./p(:,4))./Yrf(:,f); end
If all response features are linear in the parameters this function does not need to be defined. Here we must first find out which response features (if any) are user-defined. This subfunction allows the model parameters to be reconstructed from the response features we have been given.
![]() | Subfunctions | Checking into MBC | ![]() |