4
$\begingroup$

Consider the functions

\[Lambda][n_] := ((n \[Pi])/L)^2

\[ScriptCapitalX][
x_] := \[ScriptCapitalC][1] Cos[Sqrt[\[Lambda][n]] x]

\[ScriptCapitalT][t_] := 50 E^(-\[Lambda] t)

to give the Sum product solution

\[ScriptCapitalU][x_, 
t_, \[ScriptCapitalN]_] := \[ScriptCapitalX][x] \[ScriptCapitalT][t]

Notice that the 2D and 3D plot of the Sum product solution, respective are

Plot[Evaluate@
ReplaceAll[
Table[\[ScriptCapitalX][x] \[ScriptCapitalT][t], {n, 1, 3}, {L, 1, 
 1}], {\[ScriptCapitalC][1] -> 1, \[Lambda] -> 1, t -> 0}], {x, 0,
1}, PlotLegends -> "Expressions", AxesLabel -> {"x", "t"}, 
PlotLabel -> "2D Plot Behaviour for \[ScriptCapitalU](x,t)"]

and

Plot3D[ReplaceAll[
Table[\[ScriptCapitalU][x, t, \[ScriptCapitalN]], {n, 1, 3}, {L, 1, 
1}], {\[ScriptCapitalC][1] -> 1, \[Lambda] -> 1}], {t, 0, 1}, {x, 
0, 1}, AxesLabel -> Automatic, 
PlotLabel -> "3D Plot Behaviour for \[ScriptCapitalU](x,t)"]

If you rotate the 3D point such that the x and t plots points "towards" you, you are able to observe that they corresponds qualitatively to the 2D plot.

enter image description here enter image description here In the case of the 3D plot, how do I match the different colours to different "n" for n=1 to n=3?

Any help is appreciated.

$\endgroup$
  • 1
    $\begingroup$ in Plot3D[...] add the options Evaluated->True or wrap the first argument with Evaluate as you did in Plot. $\endgroup$ – kglr Jan 22 '18 at 8:10
  • $\begingroup$ @kglr It doesn't work $\endgroup$ – Physkid Jan 22 '18 at 8:13
5
$\begingroup$
Plot3D[Evaluate@
  ReplaceAll[Table[\[ScriptCapitalU][x, t, \[ScriptCapitalN]], {n, 1, 3}, {L, 1, 1}], 
 {\[ScriptCapitalC][1] -> 1, λ -> 1}], {t, 0, 1}, {x, 0, 1}, 
  AxesLabel -> Automatic, 
  PlotLabel -> "3D Plot Behaviour for \[ScriptCapitalU](x,t)"]

enter image description here

Note: Interestingly, the combination of options Evaluated ->True + PlotStyle -> {Red, Green, Blue}, which works in version 9, does not work in version 11.2 (on Wolfram Cloud).

$\endgroup$
  • $\begingroup$ my code bellow works in version 11.2 (PC client). $\endgroup$ – PureLine Jan 23 '18 at 7:34
4
$\begingroup$
\[Lambda][n_] := ((n \[Pi])/L)^2
\[ScriptCapitalX][x_] := \[ScriptCapitalC][1] Cos[Sqrt[\[Lambda][n]] x]
\[ScriptCapitalT][t_] := 50 E^(-\[Lambda] t)
\[ScriptCapitalU][x_, t_, \[ScriptCapitalN]_] := \[ScriptCapitalX][x] \[ScriptCapitalT][t]

Plot3D[Evaluate@ (* Step 2: enforce the evaluation before configuring the colors *)
  ReplaceAll[Table[\[ScriptCapitalU][x, t, \[ScriptCapitalN]], {n, 1, 3}, {L, 1, 1}], {\[ScriptCapitalC][1] -> 1, \[Lambda] -> 1}], {t, 0, 1}, {x, 0, 1}, 
  AxesLabel -> Automatic, PlotLabel -> "3D Plot Behaviour for \[ScriptCapitalU](x,t)",
  PlotStyle -> {Red, Green, Blue}] (* Step 1: use PlotStyle to set up color for each plot surface *)

enter image description here

$\endgroup$
  • $\begingroup$ how is this different from the earlier answer below?:) $\endgroup$ – kglr Jan 22 '18 at 8:24
  • $\begingroup$ @kglr maybe we submit the answer simultaneously... however, I bring out a way to customize the colors by PlotStyle. 囧rz $\endgroup$ – PureLine Jan 22 '18 at 8:26
  • $\begingroup$ PureLine, thanks. Good point. $\endgroup$ – kglr Jan 22 '18 at 8:37

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.