0

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).

TGram
  • 11
  • 2
  • 3
    A web search for mathematica stackexchange simultaneous fit will turn up several relevant hits. – Daniel Lichtblau Oct 22 '18 at 15:30
  • However, I could not find relevant (similar) cases that I could implement. – TGram Oct 22 '18 at 15:33
  • 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, – rhermans Oct 22 '18 at 15:43
  • 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. – JimB Oct 22 '18 at 16:51
  • @JimB I have made a revision you have suggested but still I do not get a reliable output (no fit is shown). – TGram Oct 22 '18 at 16:55
  • Your revised code works fine for me on Mathematica 10.4 (Windows 10). What version and operating system are you using? – JimB Oct 22 '18 at 16:59
  • @JimB Mathematica 11.3 (Windows 10) – TGram Oct 22 '18 at 17:01
  • Fixed, works fine – TGram Oct 22 '18 at 17:04
  • By the way, why in https://mathematica.stackexchange.com/questions/15905/combined-fitting-via-nonlinearmodelfit Kronecker's deltas are used? – TGram Oct 22 '18 at 17:17

0 Answers0