How to use conditional bounds for parameters with lsqcurvefit?

2 ビュー (過去 30 日間)
Akhil
Akhil 2023 年 1 月 25 日
コメント済み: Akhil 2023 年 1 月 25 日
I am trying to fit an exponential curve to a set of data (Exponential Cumulative Distribution Function).
I would like to solve for the parameters λ, , and , however there are certain conditions with which I need to bound the parameters.
"The and are non-negative values that can be both be 0 but both values cannot be greater than 0 at the same time" as well as "The natural logarithm of λ can be any value between zero and 4."
Is there a way in which I would be be able to define these conditions using lsqcurvefit to solve for the parameters? If not how should I approach fitting this curve to my data? Below is my attempt to use lsqcurvefit without the conditional between and .
xdata = 0:7;
ydata = 100*[0 0.112543130593672 0.814735805710535 1 1 1 1 1];
lb = [log(1), 0, 0];
ub = [log(4), 7, 100]; % How to define upper bound with conditions?
fun = @(x,xdata) (1 - exp(-x(1)*(xdata-x(2))) + x(3));
x = lsqcurvefit(fun,[0, 0, 0],xdata,ydata, lb, ub)
plot(xdata, 1*ydata, '.k', 'MarkerSize', 20)
hold on
plot(xdata, 1*fun(x, xdata))
  1 件のコメント
Matt J
Matt J 2023 年 1 月 25 日
The natural logarithm of λ can be any value between zero and 4.
If 0<=log(lambda)<=4, then your bounds on lambda would be exp(0) <=lambda<=exp(4), whereas in your code, you have log(1) <=lambda<=log(4)

サインインしてコメントする。

採用された回答

Matt J
Matt J 2023 年 1 月 25 日
編集済み: Matt J 2023 年 1 月 25 日
You must divide the problem into two cases: one case where X0 is fixed at 0 and the second when Y0 is fixed at zero.
xdata = 0:7;
ydata = 100*[0 0.112543130593672 0.814735805710535 1 1 1 1 1];
lb = [exp(0), 0, 0];
ub = [exp(4), 7, 100];
%Case 1: Y0=0
fun = @(x,xdata) (1 - exp(-x(1)*(xdata-x(2))) );
x = lsqcurvefit(fun,[0, 0],xdata,ydata, lb(1:2), ub(1:2));
Initial point is a local minimum. Optimization completed because the size of the gradient at the initial point is less than the value of the optimality tolerance.
sol{1}=[x(1),x(2),0];
%Case 2: X0=0
fun = @(x,xdata) (1 - exp(-x(1)*(xdata)) +x(2));
x = lsqcurvefit(fun,[0, 0],xdata,ydata, lb([1,3]), ub([1,3]) );
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
sol{2}=[x(1) 0 x(2)];
Now test each solution and see which gives the best resnorm. Clearly, sol{2} is the best:
Fun = @(x) norm( 1 - exp( -x(1)*(xdata-x(2)) ) + x(3) -ydata);
Fun(sol{1})
ans = 235.7671
Fun(sol{2})
ans = 112.7009
  1 件のコメント
Akhil
Akhil 2023 年 1 月 25 日
Thank you, definitely a much simpler solution than what I was expecting!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNonlinear Optimization についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by