1
$\begingroup$

I am aware that similar questions have been asked previously. I am new to Mathematica. I tried all the suggested solutions but unfortunately did not manage to solve my problem. Any help would be highly appreciated.

I have two extremely small datasets:

dat1={{2, 1.4725}, {3, 1.4612}, {4, 1.4587}, {5, 1.4580}}

dat2={{2, 1.4733}, {3, 1.4608}, {4, 1.4591}}

I have two models:

mod1 = a + b Exp[-c x]

mod2 = a + d Exp[-e x]

The parameter a has to be the same for both the models, but needs to be obtained from fitting dat1 and dat2 to mod1 and mod2, respectively. How do I find an optimal fit for all five parameters {a,b,c,d,e} from these two small data sets?

$\endgroup$
  • $\begingroup$ What was your problem when applying the method suggested, for instance, here ? $\endgroup$ – b.gates.you.know.what Nov 29 '17 at 13:15
1
$\begingroup$

An opinion: You have no business attempting to fit 6 parameters (a, b, c, d, e, and error variance) with just 8 points.

A solution ignoring the above opinion and with hope that you get more data:

Create a single data set where the points are identified as to which dataset they belong:

dat1 = {{2, 1.4725}, {3, 1.4612}, {4, 1.4587}, {5, 1.4580}};
dat2 = {{2, 1.4733}, {3, 1.4608}, {4, 1.4591}};
data = Join[Join[List /@ {1, 1, 1, 1}, dat1, 2], Join[List /@ {2, 2, 2}, dat2, 2]]
(* {{1, 2, 1.4725}, {1, 3, 1.4612}, {1, 4, 1.4587}, {1, 5, 1.458}, {2, 2,
   1.4733}, {2, 3, 1.4608}, {2, 4, 1.4591}} *)

Fit a model:

nlm = NonlinearModelFit[data, 
   a + Boole[y == 1] b Exp[-c x] + Boole[y == 2] d Exp[-e x], {a, b, c, d, e}, {y, x}];
nlm["BestFitParameters"]
(*{a -> 1.45814, b -> 0.331115, c -> 1.5689, d -> 0.437684, e -> 1.68206} *)
Show[ListPlot[{dat1, dat2}], 
 Plot[{nlm[1, x], nlm[2, x]}, {x, Min[data[[All, 2]]], Max[data[[All, 2]]]}]]

Data and fit for two equations

$\endgroup$
0
$\begingroup$

Hi not elegant solution(but works)

dat1 = {{2, 1.4725}, {3, 1.4612}, {4, 1.4587}, {5, 1.4580}};
dat2 = {{2, 1.4733}, {3, 1.4608}, {4, 1.4591}};
fun[a_, b_, c_, d_, e_] :=
Module[{rez1, rez2}, 
 rez1 = Total[(dat1[[All, 2]] - (a + b*Exp[-c*dat1[[All, 1]]]))^2];
rez2 = Total[(dat2[[All, 2]] - (a + d*Exp[-e*dat2[[All, 1]]]))^2];
rez1 + rez2]
NMinimize[fun[a, b, c, d, e], {a, b, c, d, e}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.