How to skip the element that is 'inf' value where fitting a curve
3 views (last 30 days)
Show older comments
Hello, I have been trying to get some constant values for a given set of experimental data. The fitting equation is below:
k*t = a-ln((Cm/C)-1) where a and k value needs to be find out. C is the output at different time t. Cm = maximum value of the C data at anytime t. So, obviously at some point ln((Cm/C)-1) is giving me 'inf' value and the procedure is not able to initiate at any initial guess of k and a value.
How to proceed with the problem for the solution. I have been trying using 'lsqcurvefit' which says 'Objective function is returning undefined values at initial point. lsqcurvefit cannot continue'
0 Comments
Accepted Answer
Star Strider
on 18 Aug 2014
Edited: Star Strider
on 18 Aug 2014
I would use this equation for ‘Cfit’ as my objective function:
% b(1) = a, b(2) = k, <— Designate Parameter Vector ‘b’
Cm = ... % <— Supply a value for ‘Cm’
Cfit = @(b,t,Cm) Cm./(exp(b(1)-b(2).*t) + 1); % Objective Function
b0 = rand(2,1); % Initial Parameter Estimate
B = lsqcurvefit(@(b,t) Cfit(b,t,Cm), b0, t, C) % Estimate Parameters
a = B(1);
k = B(2);
That should work. (Tested with simulated data for ‘t’ and ‘C’.)
You needed to solve for ‘C’ as a function of ‘t’ to make it work. (It’s a three or four line derivation.)
2 Comments
Star Strider
on 19 Aug 2014
My pleasure!
‘Cfit’ is the function (as an anonymous function here) that fits your data. (It is known as the ‘objective function’ in nonlinear parameter estimation terms.) It is your original expression, solved for ‘C’ as a function of ‘t’, specifically:
C(t) = Cm /(exp(a-k*t)+1)
however it has to be stated slightly differently in anonymous function form, and in its use in lsqcurvefit, for it to work in MATLAB to fit your data. See the documentation on Anonymous Functions for details.
More Answers (0)
See Also
Categories
Find more on Nonlinear 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!