0
$\begingroup$

This question already has an answer here:

I have two following data-sets:

data1={{386.10999999999996`, 2.99831`}, {385.07`, 4.26322`}, {384.03`, 
   5.08508`}, {383.12`, 5.58428`}, {382.08`, 
   6.13079`}, {381.03999999999996`, 6.53994`}, {380.`, 
   6.82545`}, {378.96`, 7.00631`}, {378.44`, 
   7.06699`}, {377.91999999999996`, 7.23226`}, {377.4`, 
   7.43319`}, {376.88`, 7.39476`}, {376.35999999999996`, 
   7.59252`}, {375.96999999999997`, 7.852`}, {375.84`, 
   7.84731`}, {375.58`, 7.96505`}, {375.32`, 8.05784`}, {375.19`, 
   8.16459`}, {375.05999999999995`, 8.16023`}, {374.92999999999995`, 
   8.09303`}, {374.92999999999995`, 8.1093`}, {374.79999999999995`, 
   8.16085`}, {374.66999999999996`, 8.29507`}, {374.53999999999996`, 
   8.29715`}, {374.40999999999997`, 8.20119`}};
data2={{386.12638`, 1.16966`}, {385.10276`, 1.44312`}, {384.07914`, 
   1.55275`}, {383.05552`, 1.67674`}, {382.03189999999995`, 
   1.70782`}, {381.00827999999996`, 1.75575`}, {379.98465999999996`, 
   1.8141`}, {378.96103999999997`, 2.04406`}, {377.93742`, 
   2.14611`}, {377.42561`, 2.24514`}, {376.9138`, 
   2.49293`}, {376.40198999999996`, 2.5167`}, {375.99249`, 
   2.52265`}, {375.78774`, 2.55287`}, {375.58312`, 
   2.51717`}, {375.37836999999996`, 2.49299`}, {375.17361999999997`, 
   2.54704`}, {375.07131`, 2.60758`}, {374.96887`, 
   2.53487`}, {374.86656`, 2.65357`}, {374.76412`, 
   2.6157`}, {374.66180999999995`, 2.71675`}, {374.50827999999996`, 
   2.63708`}, {374.45705999999996`, 2.75287`}, {374.35474999999997`, 
   2.81088`}};

How can I fit two polynomials simulatneously (below, $A$ intentionally are the same)? $$F(x)=(4A+2B)x^2$$ $$G(x)=4Ax^2$$

When I try to employ solution proposed in Combined fitting via NonlinearModelFit

allData =  Join[{1, Sequence @@ #} & /@ data1, {2, Sequence @@ #} & /@ data2];
f[x_]:= (4A+2B)*x^2
g[x_]:= 4A*x^2
myF[index_, x_] :=  KroneckerDelta[index - 1] f[x] + KroneckerDelta[index - 2] g[x]

nlm = NonlinearModelFit[allData, myF[index, x], {A, B}, {index, x}];

Show[ListPlot[{data1, data2}],  Plot[{nlm[1, x], nlm[2, x]}, {x, 374, 387}]]

as a result I do not get any fit (no fit is plotted).

$\endgroup$

marked as duplicate by Daniel Lichtblau, rhermans, m_goldberg, JimB, Henrik Schumacher Oct 24 '18 at 15:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    $\begingroup$ A web search for mathematica stackexchange simultaneous fit will turn up several relevant hits. $\endgroup$ – Daniel Lichtblau Oct 22 '18 at 15:30
  • $\begingroup$ However, I could not find relevant (similar) cases that I could implement. $\endgroup$ – TGram Oct 22 '18 at 15:33
  • $\begingroup$ Welcome to Mma.SE. Start by taking the tour now and learning about asking and what's on-topic. Always edit if improvable, show due diligence, give brief context, include minimal working example of code and data in formatted form. You need to explain in which way your problem is different from the other solutions available, otherwise your question will be closed as a duplicate, $\endgroup$ – rhermans Oct 22 '18 at 15:43
  • $\begingroup$ You have multiple typos. You use A and B in the function definitions and then a and b in NonlinearModelFit. And the range in the Plot is {x, 1, 25} when it should be something closer to the observed data: {x, 374, 387}. Once those typos are fixed, things run but you get an extremely poor fit. $\endgroup$ – JimB Oct 22 '18 at 16:51
  • $\begingroup$ @JimB I have made a revision you have suggested but still I do not get a reliable output (no fit is shown). $\endgroup$ – TGram Oct 22 '18 at 16:55