0
$\begingroup$

I have the following data

setA = {{0.0001, 0.5, 0.5000000020621443`}, {0.01, 
    0.9090909090909091`, 0.9089263228218556`}, {0.1, 
    0.9803921568627451`, 0.9685612823447454`}, {1, 
    0.9951923076923077`, 0.8965347385041562`}, {10, 
    0.9975062344139651`, 0.8370285555286358`}, {1000, 
    0.9988901220865705`, 0.809761243637952`}, {10000, 
    0.9994556341861731`, 0.8080295675491966`}};

setB = {{0.0001, 0.5, 1.1754907046612933`*^-8}, {0.01, 
     0.9090909090909091`, 0.0001497516481925709`}, {0.1, 
     0.9803921568627451`, 0.013113265479399906`}, {1, 
     0.9951923076923077`, 0.36837218815129213`}, {10, 
     0.9975062344139651`, 4.605802823908744`}, {1000, 
     0.9988901220865705`, 495.77609116353705`}, {10000, 
     0.9994556341861731`, 4985.705218556087`}};;

which has the form $ \{\omega, \mu , a \}$ for setA and $ \{\omega, \mu , b \}$ for setB. Now I want to fit setA to $$ \mu \Bigl(a_1-a_2 \text{erf}(\text{Log}[\omega]\sqrt{a_3 \mu})\Bigl) $$ and fit setB to $$ \lvert -b_1 \text{exp}\bigl( b_2 \text{Log}[\omega]\mu+ \frac{\mu \omega}{2} \bigr) \rvert $$ I tried these following codes

fitA = NonlinearModelFit[
  setA, \[Mu] (a1 - a2 Erf[Log[\[Omega]] Sqrt[a3 \[Mu]]]), {a1, a2, 
   a3}, {\[Mu], \[Omega]}]

and

fitB = NonlinearModelFit[setA, 
  Abs[-b1 Exp[b2 Log[\[Omega]]] \[Mu] + (b3 \[Mu] \[Omega])/2], {b1, 
   b2, b3}, {\[Mu], \[Omega]}]

but they don't work specially for setA. It returns this error:

NonlinearModelFit::nrlnum: The function value {-0.499987023189+0.0354938976555 I,-0.907628435515+5.02574192093 I,-0.955582409275+31.8756408087 I,-0.766746007804+242.692381728 I,0.46085875147 +4082.71039099 I,128.978969456 +5.26288648114*10^6 I,1297.07927743 +9.21370092281*10^8 I} is not a list of real numbers with dimensions {7} at {a1,a2,a3} = {0.1297887307,987.212217384,-1981.56646201}.

Any idea to fit my data to formula?

Addendum

I have determined the values of all these parameters using a two-step fitting (first, fit to $\omega$ and then fit to $\mu$). They have the following values which match to my real data:

$$ a_1=0.9,\; a_2=0.096,\; a_3=1.333,\; b_1=0.1,\; b_2=0.5 $$

but I want to reproduce them using a one-step fitting to make sure my results were true. In fact this is a cross-checking.

$\endgroup$
4
  • 1
    $\begingroup$ "They don't work", what error message do you get? $\endgroup$ Aug 20 '21 at 5:52
  • $\begingroup$ @MariusLadegårdMeyer I added the error. $\endgroup$
    – Wisdom
    Aug 20 '21 at 6:17
  • $\begingroup$ What do you mean by "your real data"? That is different from setA? Is your "2-step fitting" a recognized fitting technique? $\endgroup$
    – JimB
    Aug 20 '21 at 17:05
  • $\begingroup$ I meant the correct values of parameters $\endgroup$
    – Wisdom
    Aug 20 '21 at 17:28
1
$\begingroup$

Add the constraint a3>0

fitA = NonlinearModelFit[setA, {\[Mu] (a1 - a2 Erf[Log[\[Omega]] Sqrt[a3 \[Mu]]]), 
a3 > 0}, {a1, a2, a3}, { \[Omega]\[Mu]}]

fitA["BestFitParameters"]
(*{a1 -> 0.905805, a2 -> 0.0872282, a3 -> 2.49084}*)


Show[{ Plot3D[fitA[ \[Omega],\[Mu]], {\[Omega], 0, 10000}, {\[Mu], .5, 1},PlotStyle -> Opacity[.2]], Graphics3D[{Red, Point[setA]}] }]

enter image description here

$\endgroup$
6
  • $\begingroup$ Thanks, but why you set $\mu$ from 0 to 10000? it's the range of $\omega$! $\endgroup$
    – Wisdom
    Aug 20 '21 at 6:29
  • $\begingroup$ Please see the addendum $\endgroup$
    – Wisdom
    Aug 20 '21 at 6:36
  • $\begingroup$ @wisdom See my corrected answer $\endgroup$ Aug 20 '21 at 6:46
  • $\begingroup$ Thanks it returns very better results, but a3 doesn't match to real a3. few data can be the reason? If I add more points to my data, it will yield the correct results? $\endgroup$
    – Wisdom
    Aug 20 '21 at 7:13
  • $\begingroup$ @wisdom Probably yes! $\endgroup$ Aug 20 '21 at 8:13

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.