Global optimization using symbolic equations
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zine
el 8 de Mayo de 2016
Respondida: Walter Roberson
el 9 de Mayo de 2016
I want to do global optimization using Multistart or GlobalSearch (curve fitting mainly with lsqcurvefit and fmincon); I want to use symbolic math toolbox because it gives me more flexibility; the problem is that I do not know how to set my problem; my objectives are as follows:
- Enter the model as string expression (one by one, the strings are in cell array and each time I press enter, the solver will take one model and try to find the best fit on the same experimental data- it is a kind of testing the validity of the model or its representativity of the data- models are of different number of parameters between 10 to 16 parameters, data points are about 1500 sets)
- Convert the string to symbolic expression
- Calculate the derivatives
- Convert the symbolic to matlab function
- Pass it to solver and find optimum parameters (with the ability to set the range or fix the parameter)
the solver needs an array of parameters, but I do not have the parameters in a form of array like par(1), par(2) ..., I tried to use symvar but it extracts the parameters in the expression only; in short I am lost so any kind of help or idea will be appreciated. I found a good document ( here ) by Alan Weiss which is very nice document but I could not ajust it to my case, but the idea is similar; thanks in advance.
0 comentarios
Respuesta aceptada
Walter Roberson
el 9 de Mayo de 2016
YourSymbolicExpression = sym(YourString);
SV = symvar(YourSymbolicExpression);
f = matlabFunction(YourSymbolicExpression, {SV});
gr = gradient(YourSymbolicExpression, SV);
grf = matlabFunction(gr, 'vars', {SV});
hess = hessian(YourSymbolicExpression, SV);
hessf = matlabFunction(hess, 'vars', {SV});
Now f and grf will be the handles of anonymous function which take a row vector of values. f would in itself be suitable as an objective function and grf would be suitable as a gradient function. However if you are using gradient functions (or hessian) with fmincon trust-region-reflective then you need pack them all into one function that only assigns outputs conditionally. You can do that with something like,
Frm = @(x) FunGrad(x, f, grf, hessf);
and pass Frm to fmincon,
where FunGrad is something like,
function [F,g, h] = FunGrad(x, Fun, Grad, Hess)
F = Fun(x);
if nargout > 1
g = Grad(x);
end
if nargout > 2
h = Hess(x);
end
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display 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!