2
$\begingroup$

I have some code that I am happy with:

 ClearAll["Global`*"]; Show[
   Table[sol = 
     NDSolve[{D[xtraj[t], 
         t] == (Sinh[2 xtraj[t] (t - 2)])/(Cosh[2 xtraj[t] (t - 2)]), 
       xtraj[0] == n}, xtraj[t], {t, 0, 4}];
     ParametricPlot[{xtraj[t], t} /. sol, {t, 0, 4}, 
   PlotRange -> All], {n, -3, 4 - 1, 1}]]

But I want to add a 3rd axis with the following equation:

 P1 = (E^(-(1/2) (t + x - xi)^2 σ^2) Sqrt[π/ 2] σ (1 + E^(2 x (t - xi) σ^2) + 
      2 E^(x (t - xi) σ^2) Cos[2 k0 x]))

REMEMBER: I am using the value of xtraj[t] to plot, not sol.

So it will be a 3D plot with: xtraj[t], t, P1.

Any help would be much appreciated.

$\endgroup$
3
  • $\begingroup$ is this close to what you need: k0 = 1; \[Sigma] = 1; xi = 1; p1 = (E^(-(1/2) (t + x - xi)^2 \[Sigma]^2) Sqrt[\[Pi]/2] \[Sigma] (1 + E^(2 x (t - xi) \[Sigma]^2) + 2 E^(x (t - xi) \[Sigma]^2) Cos[2 k0 x])); Show[Table[ sol = NDSolve[{D[xtraj[t], t] == (Sinh[2 xtraj[t] (t - 2)])/(Cosh[2 xtraj[t] (t - 2)]), xtraj[0] == n}, xtraj[t], {t, 0, 4}]; ParametricPlot3D[{xtraj[t], t, p1 /. x -> xtraj[t]} /. sol, {t, 0, 4}, PlotRange -> All], {n, -3, 4 - 1, 1}]]? $\endgroup$
    – kglr
    May 31 '18 at 6:06
  • $\begingroup$ Looks close but it only shows lines, really need a sheet. $\endgroup$
    – Betty
    May 31 '18 at 6:09
  • $\begingroup$ Betty, noticed you haven't cast any votes. Please see MichaelE2's comment here . $\endgroup$
    – kglr
    May 31 '18 at 7:18
1
$\begingroup$
k0 = 1; σ = 1; xi = 1;
p1 = (E^(-(1/2) (t + x - xi)^2 σ^2) Sqrt[π/2] σ (1 + E^(2 x (t - xi) σ^2) + 
   2 E^(x (t - xi) σ^2) Cos[2 k0 x]));
data3d = Flatten[Table[sol = NDSolve[{D[xtraj[t], t] == (Sinh[2 xtraj[t] (t - 2)])/
    (Cosh[2 xtraj[t] (t - 2)]), xtraj[0] == n}, xtraj[t], {t, 0, 4}];
  Table[{xtraj[t], t, p1 /. x -> xtraj[t]} /. sol, {t, 0, 4, .1}], {n, -3, 4 - 1, 1}], 2];
lpp3d = ListPlot3D[data3d, PlotRange -> All, Mesh -> None];

pp3d = Show[Table[sol = NDSolve[{D[xtraj[t], t] == (Sinh[2 xtraj[t] (t - 2)])/
   (Cosh[2 xtraj[t] (t - 2)]),  xtraj[0] == n}, xtraj[t], {t, 0, 4}]; 
 ParametricPlot3D[{xtraj[t], t, p1 /. x -> xtraj[t]} /. sol, {t, 0, 4}, 
    PlotRange -> All, PlotStyle -> Directive[Red, Thick]], {n, -3, 4 - 1, 1}]];


Show[lpp3d, pp3d]

enter image description here

An alternative approach is to use ParametricNDSolveValue to get the function xtraj parametrizes by n and use it in three-argument form of ParametricPlot3D:

xtraj2 = ParametricNDSolveValue[{D[y[t], t] == Sinh[2 y[t] (t - 2)]/Cosh[2 y[t] (t - 2)], 
 y[0] == n}, y, {t, 0, 4}, {n}];
ParametricPlot3D[{xtraj2[n][t], t, p1 /. x -> xtraj2[n][t]}, {t, 0, 4}, {n, -4, 4}, 
  PlotRange -> All, BoxRatios -> {1, 1, 1/2}, 
  MeshFunctions -> {#5 &}, Mesh -> {Range[-3, 3]}, 
  MeshStyle -> Directive[Red, Thick], ColorFunction -> "Rainbow"]

enter image description here

$\endgroup$
8
  • $\begingroup$ That is looking nice - how about the sheet and the lines together that would really show the detail. $\endgroup$
    – Betty
    May 31 '18 at 6:44
  • $\begingroup$ Thanks - you are super helpful. Is the an option to change the colour of the sheet? $\endgroup$
    – Betty
    May 31 '18 at 6:56
  • $\begingroup$ @Betty, try PlotStyle->Blue or ColorFunction ->"Rainbow" in ListPlot3D. $\endgroup$
    – kglr
    May 31 '18 at 7:02
  • $\begingroup$ Thanks so much kglr $\endgroup$
    – Betty
    May 31 '18 at 7:04
  • $\begingroup$ I perfer the one before it - but what about opacity of the sheet? $\endgroup$
    – Betty
    May 31 '18 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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