From: eric g on
Hello Group,
In the example below I want to do a fitting "exploiting" the correlation
between y1 and y2 rather than separate them like I did. Like a 2D
fitting thing.
Also, in NonlinearModelFit, I dont like treating 1/(1+b) like another
parameter.

how to do it?

best regards,
Eric

(* my model *)
b = 1;
k = 1/2;
y1[t_] = (b + Exp[-k*t])/(1 + b);
y2[t_] = (1 - Exp[-k*t])/(1 + b);

(* my measurements *)
dat1 = Table[{t, y1[t] + RandomReal[{-1, 1}]/20}, {t, 0, 10, .1}];
dat2 = Table[{t, y2[t] + RandomReal[{-1, 1}]/20}, {t, 0, 10, .1}];

Plot[{y1[t], y2[t]}, {t, 0, 10}, Epilog -> {{Red, Point[dat1]}, {Blue,
Point[dat2]}}, PlotStyle -> {Red, Blue}]

(*FITTING*)
(* results with dat1: *)
Clear[b, k];
Normal[NonlinearModelFit[dat1, (b + Exp[-k*t])/(1 + b), {b, k}, t]]
0.504916 (0.980528 + E^(-0.492309 t))

(* results with dat2: *)
Clear[b, k];
Normal[NonlinearModelFit[dat2, (1 - Exp[-k*t])/(1 + b), {b, k}, t]]
0.494348 (1 - E^(-0.524777 t))



From: Kevin J. McCann on
How about something like this. I assume that "in reality" y2=1-y1, and
transform the "data" y2, then I just roll my own least squares fit.

Kevin

(*my measurements*)
dat1 = Table[{t, y1[t] + RandomReal[{-1, 1}]/20}, {t, 0, 10, .1}];
dat2 = Table[{t, y2[t] + RandomReal[{-1, 1}]/20}, {t, 0, 10, .1}];
X = dat1[[All, 1]];
Y1 = dat1[[All, 2]];
Y2 = dat2[[All, 2]];
Y = Join[dat1, Transpose[{X, 1 - Y2}]];
ListPlot[Y]
X = dat1[[All, 1]];
Y1 = dat1[[All, 2]];
Y2 = dat2[[All, 2]];
Clear[f, \[Kappa], \[Beta]]
f[\[Kappa]_, \[Beta]_] :=
Total[((\[Beta] + E^(-\[Kappa] #[[1]]))/(1 + \[Beta]) - #[[2]])^2 & /@
Y]
FindMinimum[f[\[Kappa], \[Beta]], {\[Kappa], 1}, {\[Beta], 1}]

eric g wrote:
> Hello Group,
> In the example below I want to do a fitting "exploiting" the correlation
> between y1 and y2 rather than separate them like I did. Like a 2D
> fitting thing.
> Also, in NonlinearModelFit, I dont like treating 1/(1+b) like another
> parameter.
>
> how to do it?
>
> best regards,
> Eric
>
> (* my model *)
> b = 1;
> k = 1/2;
> y1[t_] = (b + Exp[-k*t])/(1 + b);
> y2[t_] = (1 - Exp[-k*t])/(1 + b);
>
> (* my measurements *)
> dat1 = Table[{t, y1[t] + RandomReal[{-1, 1}]/20}, {t, 0, 10, .1}];
> dat2 = Table[{t, y2[t] + RandomReal[{-1, 1}]/20}, {t, 0, 10, .1}];
>
> Plot[{y1[t], y2[t]}, {t, 0, 10}, Epilog -> {{Red, Point[dat1]}, {Blue,
> Point[dat2]}}, PlotStyle -> {Red, Blue}]
>
> (*FITTING*)
> (* results with dat1: *)
> Clear[b, k];
> Normal[NonlinearModelFit[dat1, (b + Exp[-k*t])/(1 + b), {b, k}, t]]
> 0.504916 (0.980528 + E^(-0.492309 t))
>
> (* results with dat2: *)
> Clear[b, k];
> Normal[NonlinearModelFit[dat2, (1 - Exp[-k*t])/(1 + b), {b, k}, t]]
> 0.494348 (1 - E^(-0.524777 t))
>
>
>

 | 
Pages: 1
Prev: Random points in triangle
Next: Convex hull in 3D