Fit multivariable objective function using fminsearch
4 views (last 30 days)
Show older comments
I have been trying to fit bi-exponential function with 4 variables using fminsearch. I am having difficulty to formulate it in correct way. can you please help me to work it out. (The code is successfully run for lsqnonlin but results are very unreasonable)
b=[50 400 800]; ydata=[850 400 90];
f=@(x,b) x(1)*(x(2)*exp(-x(3)*b)+(1-x(2))*exp(-x(4)*b));
x0=[950,0.3,0.002,0.01];
options = optimset('MaxFunEvals',1e9,'MaxIter',1e9,'TolFun', 1e-8, 'TolX', 1e-8);
X=fminsearch(f,x0,options);
0 Comments
Accepted Answer
Star Strider
on 15 Oct 2015
You cannot do what you want. You have three data pairs, so you can fit a maximum of three parameters, not the four you want to fit. (Consider fitting a line that requires two parameters — slope and intercept — through a point — one data pair. You can fit an infinite number of lines, all of which are ‘correct’.) You do not know what your data are except where you measure them, so interpolating to create more ‘data’ is not an acceptable solution. So regardless of the solver you use, you are not going to get reliable parameter estimates.
You are also missing a cost function in your code. You need to minimise this instead of ‘f’:
SSECF = @(x) sum((f(x,b)-ydata).^2); % Sum-Squared-Error Cost Function
X=fminsearch(SSECF,x0,options);
You still will not get reliable parameter estimates, but at least the code will be correct!
More Answers (0)
See Also
Categories
Find more on Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!