# Change Equation E(T,u) and N(T,u) in T(E,N) and u(E,N)

I am pretty new on mathematica and I have three functions, each defined by an analytic expression:

Nf = 2.5;
p0 = ((16 + 10.5 Nf)*π^2)/90;
ζ = M/T;
p[T_, M_] = T^4 (p0 + Nf (1/18 (ζ)^2 + 1/(324*π^2) (ζ)^4)) //FullSimplify;
e[T_, M_] = 3 p[T, M] // FullSimplify;
n[T_, M_] = D[p[T, M], M] // FullSimplify;


I have these equations, but I need to create a new table with T as a function of e and n and M (for $$\mu$$).

I heard that I have to make a table of these functions; for example, this one:

Table[{T, M, n[T, M]}, {T, 0, 1., 0.1}, {M, 0, 1, 0.1}]


And after I have to do an interpolation. However, I don't know how to do this for the correct variables and how to have the correct table at the end. That is, I want to create a table like this:

Table[{e, n, T[e, n], M[e,n]}, {e, 0, 1., 0.1}, {n, 0, 1, 0.1}]


I then want to export this out to a file and set a different step for e

• Basically, you want to invert a function / solve an equation for T as a function of e and n. It seems to me, however, that there would be many solutions to that high-order polynomial equation. You will need to define which one to choose. Commented Dec 5, 2019 at 19:04
• I guess this is two equations with two unknowns, that mustbe only one solution isn't it ? Commented Dec 5, 2019 at 20:09
• Consider Solve[{x^3 + y == 1, x^3 - y == 2}, {x, y}]. Those are also two equations and two unknowns, but of course as you can see when you run that code, there are three sets of solutions because the equations involved a third-degree polynomial. You should be able to decide which solution is relevant to you . Commented Dec 5, 2019 at 20:52
• Indeed, I understood. I can choose one solution without problem with the different physics conditions I guess. Commented Dec 5, 2019 at 21:00

Clear["Global*"]

Nf = 5/2;
p0 = ((16 + 21/2 Nf)*π^2)/90;
ζ = M/T;

p[T_, M_] =
T^4 (p0 + Nf (1/18 (ζ)^2 + 1/(324*π^2) (ζ)^4)) // Simplify;

e[T_, M_] = 3 p[T, M] // Simplify;

n[T_, M_] = D[p[T, M], M] // Simplify;


Data for multidimensional interpolation needs to be in the form: {{{x1, y1,…}, f1}, {{x2, y2,…}, f2},…}. Consequently, use

EDIT: Increased range for M to extend interpolation range for n. (Thanks to Akku14)

fT = Interpolation[
Table[
{{e[T, M], n[T, M]}, T},
{T, 0, 1, 0.01}, {M, 0, 3.25, 0.01}] //
Flatten[#, 1] &,
InterpolationOrder -> 1]


The InterpolationOrder is restricted to 1 since the {e, n} grid is unstructured (non-uniform). Then function fT can be plotted directly

Plot3D[fT[ev, nv], {ev, 0, 1}, {nv, 0, 1},
AxesLabel ->
(Style[#, 14, Bold] & /@
{"e[T, M]", "n[T, M]", "T"}),
PlotRange -> {-1.5, 0.55},
PlotPoints -> 50,
ClippingStyle -> None]


You get similar results from a Table

data = Table[{ev, nv, fT[ev, nv]}, {ev, 0, 1, 0.02}, {nv, 0, 1,
0.02}] // Flatten[#, 1] &; // Quiet

ListPlot3D[data,
AxesLabel ->
(Style[#, 14, Bold] & /@ {"e[T, M]", "n[T, M]", "T"}),
PlotRange -> {-1.5, 0.55},
ClippingStyle -> None]


• Sorry @Bob Hanlon, but most of the shown T-values are roughly extrapolated and not valid, because fT is only interpolated for 0 < n < .28  Commented Dec 6, 2019 at 10:21
• @Akku14 - Thanks. Increased range for M to extend interpolation range for n Commented Dec 6, 2019 at 13:23

Why not eliminate M from equations and solve for T.

eli = Eliminate[ee == e[T, M] && nn == n[T, M], M];

TT[ee_, nn_] =
T /. Solve[eli && nn > 0 && ee > 0 && 0 < T, T, Reals] //
FullSimplify

{*   {ConditionalExpression[
Root[-108000 ee^3 + 1476225 nn^4 \[Pi]^2 +
1093500 ee nn^2 \[Pi]^2 #1^2 + 51300 ee^2 \[Pi]^2 #1^4 +
510300 nn^2 \[Pi]^4 #1^6 + 118440 ee \[Pi]^4 #1^8 +
33124 \[Pi]^6 #1^12 &, 2],
ee > 0 && 0 < nn < Root[-160 ee^3 + 2187 \[Pi]^2 #1^4 &, 2]]} *}

Plot3D[TT[e, n], {e, 0, 30}, {n, 0, 3}, AxesLabel -> {e, n, T}]


• For T it seems works, however when I did the same thing for M, I don't have anything on the Plot3D Commented Dec 6, 2019 at 12:11
• What do you mean with "when I did the same thing for M" ? Commented Dec 6, 2019 at 12:20
• I eliminate T from equations and Solve for M. eli2 = Eliminate[ee2 == e[T, M] && nn2 == n[T, M], T] and MM[ee_, nn_] = M /. Solve[eli2 && nn2 > 0 && ee2 > 0 && 0 < M, M, Reals] // FullSimplify Commented Dec 6, 2019 at 12:32
• Be carefull with function definitions. Use MM[ee2_,nn2_] = since you changed to ee2,nn2. Commented Dec 6, 2019 at 13:57
• Indeed, my bad. However I don't know if I can use this method because when I try to export in a Table, I have many Undefined element in this Table Table[{e, n, TT[e, n], MM[e, n]}, {e, 0, 1, 0.1}, {n, 0, 1, 0.1}]` Commented Dec 6, 2019 at 14:08