custom fitting / additional boudary conditions on parameters

1 visualización (últimos 30 días)
Hi there,
I am working on a custom curve fitting. It is a set of exponential functions, see below. My problem is that I have to apply constraints on paramateres g1, g2 and g3, in a way that: g1 + g2 + g3 = 1.
Can you help me out? /OT
ft = fittype(['E0*((1-g1-g2-g3)*t+g1*tau1*(1-exp(-t/tau1))+g2*tau2*(1-exp(-t/tau2))+g3*tau3*(1-exp(-t/tau3)))'],'independent', 't', 'dependent', 'y' );
opts = fitoptions( ft );
opts.Display = 'Off';
opts.Lower = [0 0 0 0 0 0 0];
opts.StartPoint = [0 0 0 0 1 10 100];
opts.Upper = [Inf 1 1 1 Inf Inf Inf];
  2 comentarios
Torsten
Torsten el 6 de Feb. de 2015
I just looked at the type of fit you defined in your question.
If you want f1+f2+f3=1 in the above fittype, the factor in front of t, namely 1-f1-f2-f3, becomes zero. Is this really what you intend ?
Best wishes
Torsten.
Onufry Torbus
Onufry Torbus el 7 de Feb. de 2015
I made a mistake before, I edited this and now should look more clear

Iniciar sesión para comentar.

Respuesta aceptada

Torsten
Torsten el 5 de Feb. de 2015
Use fmincon to be able to account for your constraints.
Best wishes
Torsten.
  3 comentarios
Torsten
Torsten el 5 de Feb. de 2015
As objective function, you provide
sum_{i=1}^{n} (y_i-f(t_i))^2
with
f(t)=A*((1-f1-f2-f3)*t+g1*t1*(1-exp(-t/t1))+g2*tau2*(1-exp(-t/t2))+g3*t3*(1-exp(-t/t3)))
and as constraints your lower and upper bounds for the parameters to be fitted together with the additional constraints from above.
Read the documentation of fmincon on how to set up the call:
Best wishes
Torsten.
Onufry Torbus
Onufry Torbus el 6 de Feb. de 2015
Editada: Onufry Torbus el 6 de Feb. de 2015
Dear Torstane,
I am beginner with Matlab and the environment is not always clear for me. I read the documentation of fmincon. As far as I understood I have to prepare mfunction file first (in a separate m file) and then make a call in my m script (curve fitting).
1. I created a file "objfun.m" as:
function f = objfun(x)
f = sum((y(i)-f(t(i))^2, i=1..n) % I am not sure if this is correct...
2.Now the call in my script:
ft = fittype(['A*((1-f1-f2-f3)*t+g1*t1*(1-exp(-t/t1))+g2*tau2*(1-exp(-t/t2))+g3*t3*(1-exp(-t/t3)))'],'independent', 't', 'dependent', 'y' );
opts = fitoptions( ft );
opts.Display = 'Off';
A = [1 1 1] % constraints
B = [0] % constraints
g0 = [0.1;0.3;0.6]; % Starting guess
[g,fval] = fmincon(@objfun,x0,A,B);
opts.Lower = [_Inf g(1) g(2) g(3) 0 0 0];
opts.StartPoint = [0 g0(1) g0(2) g0(3) 1 10 100];
opts.Upper = [Inf g(1) g(2) g(3) Inf Inf Inf];
Am I heading in good direction?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear and Nonlinear Regression 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