How to skip the element that is 'inf' value where fitting a curve

조회 수: 6 (최근 30일)
KB
KB 2014년 8월 18일
댓글: Star Strider 2014년 8월 19일
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'

채택된 답변

Star Strider
Star Strider 2014년 8월 18일
편집: Star Strider 2014년 8월 18일
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
KB
KB 2014년 8월 19일
Thank you. I am just wondering what is the purpose of using 'Cfit'? I have looked at Matlab documentation but still not clear to me.
Star Strider
Star Strider 2014년 8월 19일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by