Help fitting data to an implicit equation
6 次查看(过去 30 天)
显示 更早的评论
Hello:
I need to fit some data to the following implicit equation:
((1-y)^(1-b)/y)=exp(-kt)
t is a vector containing time values and y is a vector containing current values. for each series of data y vs t, I need to determine b and k
b has to be between 0 and 1, and k needs to be greater than 0.
I have both the optimization and the curve fitting toolboxes.
Any suggestions on what tools to use (lsqcurvefit? something else? would be very appreciated)
Thanks!
0 个评论
采纳的回答
Jeff Miller
2021-1-14
编辑:Jeff Miller
2021-1-14
I would suggest using fminsearch. The error function to be minimized would be something like:
function thiserr = err(x,y,t)
b = x(1);
k = x(2);
thiserr = sum( (((1-y).^(1-b)./y) - exp(-kt))^2 );
end
You should be able to find examples of how to use fminsearch if you need more detail on how to call it. In your case y and t are "extra parameters". Look here for information on how to handle that.
3 个评论
Jeff Miller
2021-1-16
You are welcome. That function value NaN is a bad sign. It means thiserr is NaN for all values of b and k that fminsearch has checked. You don't have any y=0 values, do you? Dividing by 0 would cause nans for all b and k.
更多回答(1 个)
John D'Errico
2021-1-16
My thought would be the lazy solution. If your model is:
((1-y)^(1-b)/y)=exp(-kt)
then log the model. That is, we know that
(1-b)*log(1-y) + k*t = log(y)
With one more step, this reduces to
-b*log(1-y) + k*t = log(y) - log(1-y)
You can compute the parameters k and b using a simple linear regression now. Thus, if y and t are column vectors, we have:
bk = [-log(1-y),t] \ (log(y) - log(1-y));
so bk is a vector of length 2, contining the estimates for b and k respectively. If you find that b or k are estimated to be something outside of the valid region, then I would first consider if this is a reasonable model, but then you could just use lsqlin to estimate them, since lsqlin does provide bound constraints.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!