MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Thread Subject: curve fitting, relationship between fitted parameters

 Subject: curve fitting, relationship between fitted parameters From: Tina Date: 3 Aug, 2012 13:30:32 Message: 1 of 7 Hello, I'm basically trying to fit data to the curve a*exp(b)+(1-a)*exp(c) How can I set the condition b
 Subject: curve fitting, relationship between fitted parameters From: Matt J Date: 3 Aug, 2012 13:37:12 Message: 2 of 7 "Tina" wrote in message ... > Hello, > > I'm basically trying to fit data to the curve > a*exp(b)+(1-a)*exp(c) > > How can I set the condition b
 Subject: curve fitting, relationship between fitted parameters From: Tina Date: 3 Aug, 2012 13:51:13 Message: 3 of 7 "Matt J" wrote in message ... > "Tina" wrote in message ... > > Hello, > > > > I'm basically trying to fit data to the curve > > a*exp(b)+(1-a)*exp(c) > > > > How can I set the condition b > Maybe reparametrize as > > a*exp(b)+(1-a)*exp(b+exp(d)) > > where we have made the change of variables c=b+exp(d) Hi Matt, Thank you for your help, this is a smart and simple idea! My equation is in reality a bit more complicated than the one above: sqrt((M0^2)*((A^2)*(exp(-2*x/B))+2*A*(1-A).*exp(-x/C).*exp(-x/B).*cos(f*x*(10^(-3))*2*pi)+((1-A)^2)*exp(-2*x/C))) where M0, A, B, C, f are parameters, x is the data. So I should just substitute exp(1/C) with exp(1/B+1/C)?
 Subject: curve fitting, relationship between fitted parameters From: Matt J Date: 3 Aug, 2012 13:56:12 Message: 4 of 7 "Matt J" wrote in message ... > "Tina" wrote in message ... > > Hello, > > > > I'm basically trying to fit data to the curve > > a*exp(b)+(1-a)*exp(c) > > > > How can I set the condition b > Maybe reparametrize as > > a*exp(b)+(1-a)*exp(b+exp(d)) > > where we have made the change of variables c=b+exp(d) =============== Better: exp(b+exp(d)) can also be parametrized exp(b)+exp(d) leading to exp(b)-a*exp(d) However, since you have no bounds on b,c and hence also not on d, you can't really try to force the values exp(b) and exp(d) to be strictly positive. At best you can force them to be non-negative by reparametrizing as b^2+a*d^2
 Subject: curve fitting, relationship between fitted parameters From: Tina Date: 3 Aug, 2012 15:01:22 Message: 5 of 7 "Matt J" wrote in message ... > "Matt J" wrote in message ... > > "Tina" wrote in message ... > > > Hello, > > > > > > I'm basically trying to fit data to the curve > > > a*exp(b)+(1-a)*exp(c) > > > > > > How can I set the condition b > > > Maybe reparametrize as > > > > a*exp(b)+(1-a)*exp(b+exp(d)) > > > > where we have made the change of variables c=b+exp(d) > =============== > > Better: exp(b+exp(d)) can also be parametrized exp(b)+exp(d) leading to > > exp(b)-a*exp(d) > > However, since you have no bounds on b,c and hence also not on d, you can't really try to force the values exp(b) and exp(d) to be strictly positive. At best you can force them to be non-negative by reparametrizing as > > b^2+a*d^2 Hi Matt, I have parameter bounds. Like 'Upper',[2*max(FitVektorY),1,200,200,1600] and something similar for lower. I tried reparametrizing, but the fit now is even worse. Isn't there a way to just tell matlab to include the condition b>c in the fitting procedure?
 Subject: curve fitting, relationship between fitted parameters From: Matt J Date: 3 Aug, 2012 15:15:10 Message: 6 of 7 "Tina" wrote in message ... > > > Isn't there a way to just tell matlab to include the condition b>c in the fitting procedure? ============= It depends what toolboxes you have. You can specify things like b>=c (non-strict equality) in FMINCON for example
 Subject: curve fitting, relationship between fitted parameters From: Matt J Date: 3 Aug, 2012 16:10:32 Message: 7 of 7 "Tina" wrote in message ... > > My equation is in reality a bit more complicated than the one above: > > sqrt((M0^2)*((A^2)*(exp(-2*x/B))+2*A*(1-A).*exp(-x/C).*exp(-x/B).*cos(f*x*(10^(-3))*2*pi)+((1-A)^2)*exp(-2*x/C))) > > where M0, A, B, C, f are parameters, x is the data. ============ BTW, you will have to get rid of the sqrt() if you are fitting with any algorithm that relies on derivatives. The function sqrt(r) is non-differentiable at r=0, which is bad for you because r=0 is where you want your residuals to be. Maybe instead of fitting y=g(x) you can instead fit y^2=g^2(x) > So I should just substitute exp(1/C) with exp(1/B+1/C)? =========== Don't know why you'd propose that. Which is supposed to be larger in this case, B or C? In any case exp(1/B+1/C) can be either greater or larger than exp(1/C) depending on the signs of B and C. Also, it might be better to parametrize as exp(B*x) and exp(C*x) instead of exp(-2*x/B) and exp(-2*x/C) because you have undefined beahvior at B=C=0.