# Fitting data to a parametric equation

I have a list of data pair and want to fit it to a parametric equation. The parametric equation is:

$h(a) = \frac{a^2}{R}-\sqrt{\frac{2\pi a w}{E^*}}$

$P(a) = \frac{4a^3E^*}{3R}-\sqrt{8\pi a E^* w}$

where $R = 25\times10^{-6}$. The fitting parameters are $E^*$ and $w$, which are both positive. A good initial guess of them is $E^* = 7.5\times 10^5$ and $w = 0.025$.

The $h$ and $P$ data points are as follows.

hvec=1.*^-9*{-543.788, -534.501, -522.833, -505.644, -487.923, -474.96, -460.52, -442.36, -424.588, -408.419, -394.821, -377.307, -360.71, -346.718, -325.011, -300.86, -282.9, -262.037, -246.88, -224.863, -211.286, -193.259, -175.539, -154.332, -132.628, -113.743, -93.71, -72.768, -46.825, -21.77, 7.576, 30.174, 56.659, 84.041, 106.232, 128.223, 153.729, 183.145, 217.012, 246.052, 270.311, 299.043, 326.504, 345.172, 358.411}
Pvec=1.*^-6*{-0.144, -0.243, -0.354, -0.464, -0.589, -0.705, -0.818, -0.936, -1.052, -1.178, -1.284, -1.394, -1.501, -1.608, -1.743, -1.872, -1.972, -2.051, -2.112, -2.203, -2.273, -2.328, -2.406, -2.5, -2.58, -2.651, -2.741, -2.835, -2.944, -3.003, -3.041, -3.077, -3.13, -3.156, -3.163, -3.151, -3.105, -3.066, -2.98, -2.879, -2.8, -2.711, -2.586, -2.462, -2.336}
ListPlot[Thread[{hvec,Pvec}], Joined -> True, PlotStyle -> Red]


Does anyone have ideas?

• I'm missing the datapoints for the parameter a. If you have datatriples {...,{ai,h[ai],P[ai]} ,...} you can solve your problem using NonlinearModelFit[]... – Ulrich Neumann Dec 8 '17 at 7:18
• What do you know about the parameters w, E*? Probably w>0, E*>0 – Ulrich Neumann Dec 8 '17 at 8:38
• Thank you, @UlrichNeumann. I have updated my question with the initial guess of $E^*$ and $w$. Since $a$ is a parametric parameter, the data points of $a$ is not known. – Wilhelm Dec 8 '17 at 22:01
• Please write the equations using inline code. You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. It is recommended that you browse the Markdown help and How to copy code from Mathematica so it looks good on this site. Once read the edit window help button ? gives quick reminders of that material. To remove from the screen, click ? again. – Jack LaVigne Dec 9 '17 at 20:47
• I have had a look at this. There is a way of using NonlinarModelfit. However, your equations are strongly dependant on the range of a so we need an estimate of this value. Can you give us one? – Hugh Dec 10 '17 at 22:45

The way of solution using NonlinearModelFit is

ai=Range[Length[hvec]];
data = Transpose[{ai, hvec  , Pvec  }];
R = 25. 10^-6;
modelh[a_] :=Normal[NonlinearModelFit[data[[All, {1, 2}]],a^2/R - Sqrt[2 Pi a w/Es], {w, Es}, a]]
modelP[a_] :=Normal[NonlinearModelFit[data[[All, {1, 3}]],4 a^3 Es/(3 R) - Sqrt[8 Pi a Es w], {w, Es}, a]]


If you're looking for one optimum E*,w for the two models the use of NMinimize is the way to solve the problem (at this point the 'implicit' parameter a is needed, unless you could eleminate a analytically from your two models!)

J = Total@Map[(a^2/R - Sqrt[2 Pi a w/Es] - h)^2 + (4 a^3 Es/(3 R) -
Sqrt[8 Pi a Es w] - P)^2 /. {a -> #[[1]], h -> #[[2]],
P -> #[[3]]} &, data] ;
NMinimize[J, {Es, w}]


That's the way to solve your problem, but you have to give additional constraints to Es>0,w>0,...(that's your system knowledge). To get the final result you must adapt parameter a !

As I mentioned in my comment it is possible to eliminate parameter a, which gives 4 models P[h].

R =.
erga = Solve[ a^2/R - Sqrt[2 Pi a w/Es] == h, a] ;
modPh = 4 a^3 Es/(3 R) - Sqrt[8 Pi a Es w] /. erga; (* 4Modells*)


NonlinearModelFit can find the optimal Fit

hp = Transpose[{hvec, Pvec}];
R = 25. 10^-6;
erg = Table[NonlinearModelFit[hp,   modPhi, {  Es, w}, h],{modPhi,modPh}]


and gives 4 FittedModel's. Which branch is the right and plausible one has to be decided...

• But how to get the fitted parameters $E^*$ and $w$? Could we fit the P-h without knowing the data of a? Since it is a parametric variable and the data points for a (avec) is a rough estimation. – Wilhelm Dec 8 '17 at 16:28
• With Fullform[] of the NonlinearModelFit- object you get an expression which includes the values for the parameters E* and w. – Ulrich Neumann Dec 9 '17 at 10:09
• Just one remark: In principle you can solve your first model h==H[a] for a, and substitue a in your second model P=f[a]. In this way you'll get four possible equations P==F[h] . If you know the right solution branch you can apply NonlinearModelFit directly . – Ulrich Neumann Dec 9 '17 at 10:47
• @ Jack LaVigne The parameter a obviously has a significance in the way it couples the two models. For a direct solution approach(NMinimize) it would be helpful to get some information about a, for example a>0 and/or the ordering of a (a1<a2<...) – Ulrich Neumann Dec 10 '17 at 10:28