Problem in the data fitting with custom equation

조회 수: 1 (최근 30일)
Somnath Kale
Somnath Kale 2021년 4월 29일
댓글: Mathieu NOE 2021년 4월 29일
Hi
I am facing some issue in the data fitting with the equation. I wanted to fit to my data with eqauation
P(t) = 2Pr (1- exp(-(t/t0)^n) (also attached in the image). and Pr <= 40 and n <=2 are the upper limits.
I wanted to fit my function for n, Pr and t0.
t = 1.00E-07 2.00E-07 5.00E-07 1.00E-06 2.00E-06 5.00E-06 1.00E-05 2.00E-05 5.00E-05 1.00E-04 2.00E-04 5.00E-04 1.00E-03 2.00E-03 5.00E-03
P(t) = 2.3800 4.4800 6.4500 9.0200 13.2400 16.2600 18.9700 22.9900 26.3300 28.7800 30.3100 31.6500 31.9500 32.0500 32.3400
if possible let me know the code also.

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 4월 29일
hello
here you are :
t = [1.00E-07 2.00E-07 5.00E-07 1.00E-06 2.00E-06 5.00E-06 1.00E-05 2.00E-05 5.00E-05 1.00E-04 2.00E-04 5.00E-04 1.00E-03 2.00E-03 5.00E-03];
P = [2.3800 4.4800 6.4500 9.0200 13.2400 16.2600 18.9700 22.9900 26.3300 28.7800 30.3100 31.6500 31.9500 32.0500 32.3400];
f = @(a,b,c,x) 2*a.*(1-exp(-(x./b).^c));
obj_fun = @(params) norm(f(params(1), params(2), params(3),t)-P);
sol = fminsearch(obj_fun, [P(end)/2,1,1]);
Pr = sol(1)
t0 = sol(2)
n = sol(3)
figure;
semilogx(t, P, '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
semilogx(t, f(Pr, t0,n, t), '-');grid on
xlabel('time t');
ylabel('P(t)');
% % gives :
% Pr = 15.9313
% t0 = 1.2114e-05
% n = 0.4339
  댓글 수: 2
Somnath Kale
Somnath Kale 2021년 4월 29일
Thanks for your kind reply!
I have one dbout: how do you seted the upper limit fot n t0 and Pr ?
is it here?
sol = fminsearch(obj_fun, [P(end)/2,1,1]);
please let know!
I also fitted the equation with fmincon but I was uable to set the upper bound.
Mathieu NOE
Mathieu NOE 2021년 4월 29일
hello
these are initial guesses , not limits;
fminsearch Multidimensional unconstrained nonlinear minimization (Nelder-Mead).
X = fminsearch(FUN,X0) starts at X0 and finds a local minimizer X of the
function FUN. FUN accepts input X and returns a scalar function value
F evaluated at X. X0 can be a scalar, vector or matrix.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by