Problem in the data fitting with custom equation

1 visualización (últimos 30 días)
Somnath Kale
Somnath Kale el 29 de Abr. de 2021
Comentada: Mathieu NOE el 29 de Abr. de 2021
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.

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 29 de Abr. de 2021
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 comentarios
Somnath Kale
Somnath Kale el 29 de Abr. de 2021
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 el 29 de Abr. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Nonlinear Optimization en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by