I have been trying to solve this plotting problem myself, and I have received a lot of very useful advice from here on Stack Exchange - but I am now at a complete loss as to how to achieve the plot I want. I am trying to do a 3D plot of the equation z = -t*Log[2*Cosh[(2y + x)/t]]
where y is defined by the transcendental equation y = Tanh[(2y + x)/t]
. Specifically the relation between the two equations is that y = - ∂z/∂x
.
In particular, y = Tanh[(2y + x)/t]
contains a supercritical bifurcation - hence, the equation has three solutions for t < 2
, and I have to pick one solution depending on the sign of x. However, I have figured out that a simple way to get around this problem, is to use that y = Tanh[(2y + x)/t]
is symmetric around x = 0
, and then simply just doing the 3D plot in two halves up to x = +/- 0.001
.
Now, I have succeeded in plotting y = Tanh[(2y + x)/t]
on my own with no problems - however, when I try to plot z = -t*Log[2*Cosh[(2y + x)/t]]
as best as I can, I get a host of error messages and a beautiful surface plot that looks very close to correct - yet, but I can tell from cuts through the surface that the plot simply isn't correct, because the slope of z just isn't fulfilling y = - ∂z/∂x
.
I am very much a noob at Mathematica, so I have done the best I could by bodging and tinkering - but I am completely stomped as to whether I am missing something mathematically or whether it is Mathematica problem, because I am not plugging y correctly into z. Could anybody possibly show me the correct way of doing this 3D plot of z, because I think I just may be in over my head? <:)
Addition:
I thought I'd better post the code I have used:
g[x_, t_] := y /. FindRoot[y == Tanh[(2 y + x)/t], {y, -5}];
p1 = ContourPlot3D[ z == - t * Log[2*Cosh[(2 g[x, t] + x)/t]] ,
{t, 0.001, 3}, {x, -1.5, -0.001}, {z, -4.0, -1.0},
MeshFunctions -> {Function[{t, x, z},
Evaluate[ D[z + t * Log[2*Cosh[(2 g[x, t] + x)/t]], z]] ]},
Mesh -> {{0}}, MeshShading -> Lighter /@ ColorData[1] /@ {1, 2},
AxesLabel -> {t, x, z}, Lighting -> "Neutral"];
k[x_, t_] := y /. FindRoot[y == Tanh[(2 y + x)/t], {y, 5}];
p2 = ContourPlot3D[ z == - t * Log[2*Cosh[(2 k[x, t] + x)/t]] ,
{t, 0.001, 3}, {x, 0.001, 1.5}, {z, -4.0, -1.0},
MeshFunctions -> {Function[{t, x, z},
Evaluate[ D[z + t * Log[2*Cosh[(2 k[x, t] + x)/t]], z]] ]},
Mesh -> {{0}}, MeshShading -> Lighter /@ ColorData[1] /@ {1, 2},
AxesLabel -> {t, x, z}, Lighting -> "Neutral"];
Show[p1, p2, PlotRange -> {{0.0, 3.0}, {-1.5, 1.5}, {-4.0, -1.0}},
ViewPoint -> {0.9*Pi, -0.45*Pi, 1.05*Pi} ]
As I wrote above, this is the product of quite a bit of tinkering and bodging because I am very new to this, so I am not completely sure what everything is doing - this just seems to do the trick. The main errors I am getting are: FindRoot::nlnum: "The function value {-5.-1.\ Tanh[(-10.+x)/t]} is not a list of numbers with dimensions {1} at {y} = {-5.}."
and ReplaceAll::reps: "{FindRoot[y==Tanh[(2\y+x)/t],{y,-5}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing."
- but I am not sure what to make of them.
ContourPlot3D
attempting to evaluateg
with symbolic arguments. You need to defineg
so that it only takes numeric arguments, likeg[x_?NumericQ, t_?NumericQ] := blah
. The same goes fork
obviously. $\endgroup$