# InterpolatingFunction in NSolve

I'm trying to get NSolve to solve a simple system of equations. It makes use of various interpolating functions (for thermodynamic properties). I can solve the system outside of NSolve by ordering the equations, but since more complex equations will be added later, I'd prefer to have Mathematica solve it.

My main issue is that I can't get Mathematica to give me values for the interpolating functions used. The equation system is much larger than this, but I get the error even on a single point in the process:

deltaTsub = -2;
Tc = 310;(*in K*)
NSolve[{
T[4] == Tc + deltaTsub,
p[4] == Evaluate[PTL[Tc, 0.5] ] ,
h[4] == Evaluate[HTP[T[4], p[4]]],
s[4] == Evaluate[STP[T[4], p[4]]]}]


with HTP (Enthalpy as a f(Temperature, Pressure)), PTL and STP being interpolating functions, defined like this:

HTP = Interpolation[Flatten[Table[{{T, p}, Enthalpy1[T, p]}, {T, 200., 330.,1.}, {p, 0.01, 0.65, 0.005}], 1]];


The solution I currently get looks like this:

NSolve[{T[4] == 308, p[4] == 0.488584,
h[4] == InterpolatingFunction[{{200., 330.}, {0.01, 0.65}}, <>][
T[4], p[4]],
s[4] == InterpolatingFunction[{{200., 330.}, {0.01, 0.65}}, <>][
T[4], p[4]]}]


It works just fine evaluating the function on pre-defined values like Tc but doesn't work once variables are introduced.

• 1: I don't think NSolve is the right function for this problem. FindRoot is probably the one you want. 2: No solution variables are defined in your code; only the equations. 3: It's not possible for readers of SE to reproduce your problem because we have no definition of Enthalpy1. Finally, your use of Evaluate does nothing here since there are no functions with a hold attribute involved. – Sjoerd Smit Jun 25 '19 at 15:35
• The expression you show as "the solution I currently get ..." is actually Mathematica's way of saying your NDSolve input expression is invalid and can't be evaluated, so I am puzzled by your further remark that "It works just fine". So I fine the question unclear. – m_goldberg Jun 25 '19 at 22:40
• @SjoerdSmit: Thanks for your answer. 1. I tried FindRoot[ {t == Tc + deltaTsub, p == PTL[Tc, 0.5] , h == HTP[t, p], s == STP[t, p]}, {{t, 300}, {p, 0.5}, {h, 270}, {s, 1.2}}] (also tried it using two additional Arguments for boundaries), but I get a "FindRoot::nlnum" error message. 2. It doesn't matter now, but as I understood it (and tested with basic examples), if you don't specify any variables, it'll try and solve for all of them, which is what I want. 3. I'm not sure I can provide a fully reproducible example, since Enthalpy1 is from a connection to a substance database. – 5plusspieldauer Jun 27 '19 at 7:34
• @m_goldberg Well, I only meant that Mathematica was able to use my function to determine p[4] but then did not manage to evaluate it for h[4]. Further: I didn't think there was anything invalid about it since I got no error message. In hindsight, that may have been naive. I do wonder exactly how it is invalid though. It just uses a user defined function in it. – 5plusspieldauer Jun 27 '19 at 7:42
• @5plusspieldauer That's strange. Since I don't have a definition for Enthalpy1, I tried HTP=STP= PTL= Interpolation[Flatten[Table[{{T,p},T p},{T,200.,330.,1.},{p,0.01,0.65,0.005}],1]];. With that, your FindRoot code works fine for me. Are you sure the interpolation functions return numeric values over the whole domain? – Sjoerd Smit Jun 27 '19 at 8:33