0
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – MarcoB
    Dec 5, 2019 at 19:04
  • $\begingroup$ I guess this is two equations with two unknowns, that mustbe only one solution isn't it ? $\endgroup$
    – G. Sophys
    Dec 5, 2019 at 20:09
  • $\begingroup$ 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 . $\endgroup$
    – MarcoB
    Dec 5, 2019 at 20:52
  • $\begingroup$ Indeed, I understood. I can choose one solution without problem with the different physics conditions I guess. $\endgroup$
    – G. Sophys
    Dec 5, 2019 at 21:00

2 Answers 2

3
$\begingroup$
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]

enter image description here

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]

enter image description here

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]

enter image description here

$\endgroup$
2
  • $\begingroup$ 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 $\endgroup$
    – Akku14
    Dec 6, 2019 at 10:21
  • $\begingroup$ @Akku14 - Thanks. Increased range for M to extend interpolation range for n $\endgroup$
    – Bob Hanlon
    Dec 6, 2019 at 13:23
2
$\begingroup$

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}]

enter image description here

$\endgroup$
6
  • $\begingroup$ For T it seems works, however when I did the same thing for M, I don't have anything on the Plot3D $\endgroup$
    – G. Sophys
    Dec 6, 2019 at 12:11
  • $\begingroup$ What do you mean with "when I did the same thing for M" ? $\endgroup$
    – Akku14
    Dec 6, 2019 at 12:20
  • $\begingroup$ 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 $\endgroup$
    – G. Sophys
    Dec 6, 2019 at 12:32
  • $\begingroup$ Be carefull with function definitions. Use MM[ee2_,nn2_] = since you changed to ee2,nn2. $\endgroup$
    – Akku14
    Dec 6, 2019 at 13:57
  • $\begingroup$ 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}] $\endgroup$
    – G. Sophys
    Dec 6, 2019 at 14:08

Your Answer

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

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