2
$\begingroup$

I have a model called qobs:

qobs=0.039 ns (T (8.314 + (8.314 - 8.314 m) Hypergeometric2F1[1., 1/m, 
    1. + 1/m, (ns/ns∞)^m] + 
  8.314 Log[-1. (A E^((0.120279 ΔE)/T))^(-1./
      m) (-1. + 1/(1. - 1. (ns/ns∞)^m))^(-1./
      m) (1/(-1. + 1. (ns/ns∞)^m))^1. (ns/
      ns∞)^(1. m) Psat[T]]) + 1. λp[T])

I have a set of data with two independent variables (ns and T):

Data = {{0, 85, 0}, {0.131592244, 85, 69.07308925}, {0.230286428, 85, 
115.4518887}, {0.255592629, 85, 126.8281889}, {0.382123633, 85, 
181.8483799}, {0.426409484, 85, 200.2798617}, {0.516246497, 85, 
237.7531003}, {0.60102227, 85, 271.3000332}, {0.642777502, 85, 
288.766803}, {0.749063545, 85, 329.4612163}, {0.760451336, 85, 
332.9712438}, {0.762981956, 85, 334.6336615}, {0, 100, 
0}, {0.074653293, 100, 39.4734225}, {0.111347284, 100, 
57.64231052}, {0.127796314, 100, 65.7007577}, {0.212572087, 100, 
104.7308741}, {0.269511039, 100, 130.1461666}, {0.29481724, 100, 
141.0225864}, {0.408695144, 100, 189.1969421}, {0.523838358, 100, 
236.109073}, {0.536491458, 100, 241.0802459}, {0.551675179, 100, 
247.1796371}, {0.58710386, 100, 261.1558457}, {0.632655021, 100, 
278.7613986}}

Other known values within the model are:

λp[85] = 6540
λp[100] = 6540
Psat[85] = 78896.6
Psat[100] = 323767
R = 8.314

I have tried using FindFit:

 FindFit[Data, qobs, {ns∞, m, A, ΔE}, { ns, T}]

And I get the error code:

FindFit::nrlnum: "The function value {0.,-69.0731+0.0051321\ (85.\ (8.314 +8.314\ Log   
[<<1>>])+1.\ λp[85.]),<<21>>,-261.156+0.0228971\ (100.\ (8.314 +8.314\ Log
[<<1>>])+1.\ λp[100.]),-278.761+0.0246735\ (100.\ (8.314 +8.314\ Log[<<1>>])+1.
\ λp[100.])} is not a list of real numbers with dimensions {25} at {ns
∞,m,A,ΔE} = {1.,1.,1.,1.}. "

I found, what I thought was a similar problem here how to avoid inducing complex numbers in FindFit

In particular the answer suggested by Oleksandr R. which involves splitting the model into explicitly real and imaginary parts and changing the data to force the imaginary part of the model to go to zero. Hence I changed my model to:

ComplexModel = Inner[#1[qobs] KroneckerDelta[i, #2] &, transformation, 
Range@Length[transformation]]

where

transformation = {Re, Im}

and I reformatted my data to:

ComplexData = {{1, 0, 85, 0}, {1, 0.131592244, 85, 69.07308925}, {1, 
0.230286428, 85, 115.4518887}, {1, 0.255592629, 85, 
126.8281889}, {1, 0.382123633, 85, 181.8483799}, {1, 0.426409484, 
85, 200.2798617}, {1, 0.516246497, 85, 237.7531003}, {1, 
0.60102227, 85, 271.3000332}, {1, 0.642777502, 85, 288.766803}, {1,
0.749063545, 85, 329.4612163}, {1, 0.760451336, 85, 
332.9712438}, {1, 0.762981956, 85, 334.6336615}, {1, 0, 100, 
0}, {1, 0.074653293, 100, 39.4734225}, {1, 0.111347284, 100, 
57.64231052}, {1, 0.127796314, 100, 65.7007577}, {1, 0.212572087, 
100, 104.7308741}, {1, 0.269511039, 100, 130.1461666}, {1, 
0.29481724, 100, 141.0225864}, {1, 0.408695144, 100, 
189.1969421}, {1, 0.523838358, 100, 236.109073}, {1, 0.536491458, 
100, 241.0802459}, {1, 0.551675179, 100, 247.1796371}, {1, 
0.58710386, 100, 
261.1558457}, {1, 0.632655021, 100, 278.7613986} {2, 0, 85, 0}, {2,
0.131592244, 85, 0}, {2, 0.230286428, 85, 0}, {2, 0.255592629, 85,
0}, {2, 0.382123633, 85, 0}, {2, 0.426409484, 85, 0}, {2, 
0.516246497, 85, 0}, {2, 0.60102227, 85, 0}, {2, 0.642777502, 85, 
0}, {2, 0.749063545, 85, 0}, {2, 0.760451336, 85, 0}, {2, 
0.762981956, 85, 0}, {2, 0, 100, 0}, {2, 0.074653293, 100, 0}, {2, 
0.111347284, 100, 0}, {2, 0.127796314, 100, 0}, {2, 0.212572087, 
100, 0}, {2, 0.269511039, 100, 0}, {2, 0.29481724, 100, 0}, {2, 
0.408695144, 100, 0}, {2, 0.523838358, 100, 0}, {2, 0.536491458, 
100, 0}, {2, 0.551675179, 100, 0}, {2, 0.58710386, 100, 0}, {2, 
0.632655021, 100, 0}}

I tried to use FindFit again:

FindFit[ComplexData, ComplexModel, {ns∞, m, 
A, ΔE}, {i, ns, T}]

however I am still getting an error code:

FindFit::nrlnum: The function value {0.,-69.0731+0.0051321 Re[85. (8.314 +Times
[<<2>>])+1. λp[85.]],<<45>>,0. +0.0228971 (831.4 Im[Log[Times[<<2>>]]]+1. Im
[λp[100.]]),0. +0.0246735 (831.4 Im[Log[Times[<<2>>]]]+1. Im[λp
[100.]])} is not a list of real numbers with dimensions {49} at {ns∞,m,A,
ΔE} = {1.,1.,1.,1.}. >>

Any help would be greatly appreciated.

$\endgroup$
2
  • $\begingroup$ Just for reference, I know the manual transformation can be a bit tedious, so I wrote a package to do it automatically. ComplexFit[Data, qobs, {ns∞, m, A, ΔE}, {ns, T}, "CoordinateSystem" -> "Real"] will do what you want. Of course, @m_goldberg's answer is absolutely correct. $\endgroup$ Mar 26, 2014 at 11:09
  • $\begingroup$ Wow, @OleksandrR. I can see where that could be a very useful package. Thank you. $\endgroup$ Mar 28, 2014 at 1:06

1 Answer 1

1
$\begingroup$

My reading of the error message you are getting is that if you try

λp[85.] = 6540
λp[100.] = 6540
Psat[85.] = 78896.6
Psat[100.] = 323767

your original formulation might work. λp[100] is not the same as λp[100.]. Similarly for λp[85] and Psat, too.

$\endgroup$
2
  • $\begingroup$ Thank you m_goldberg, that has helped! Now I've gone from a FindFit::nrlnum: error code to a FindFit::sszero: error code. I'm going to try giving it some initial values to start from and we'll see what happens. $\endgroup$ Mar 26, 2014 at 1:26
  • $\begingroup$ Bingo! Thanks again to m_goldberg. Between your suggestion of formatting as 'λp[85.] = 6540' and Oleksandr R's earlier example of how to break a FindFit model into Real and Imaginary parts, all it took were some good initial guesses for the parameter values and it all seems to be working. Fantastic! $\endgroup$ Mar 26, 2014 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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