1
$\begingroup$

I want to produce plots within the manipulate function, with the functions determined by the values that I use in the manipulate function.

I've gotten the tensor elements to work fine in producing the tensor, but I want to display the plots there, here a single set of tensor elements is plotted. The tensor elements are defined by some test values, with a picture showing the output.

Instead of explicitly writing out the values as assignments, I want them to be variables within the manipulate function that I can change with sliders


ClearAll
(*Defining constants c=speed of light \[Epsilon]=permittivity of free \
space*)
c := 3*10^8;
\[Epsilon] := 8.85*10^(-12);

(*<cx,cy,cz> =Axis of rotation (sum must equal 1,Ex Rotx= <1,0,0>or \
Rot= <1/2,1/2,Sqrt[2]/2>) \[Phi]=Rotation of sample with respect to \
the lab coordinate system \[Theta]=Angle of incindent light wave with \
incident surface*)
{cx, cy, cz} := {0, 0, 1};

(*Incoming wave vector*)
kin[\[Theta]_] := {-Sin[\[Theta]], 0, -Cos[\[Theta]]};

(*Outgoing wave vector*)
kout[\[Theta]_] := {Sin[\[Theta]], 0, Cos[\[Theta]]};

(*p-in*)
Epin[\[Theta]_] := {Cos[\[Theta]], 0, Sin[\[Theta]]};

(*s-in*)
Esin[\[Theta]_] := {0, 1, 0};

(*p-out*)
Epout[\[Theta]_] := {Cos[\[Theta]], 0, -Sin[\[Theta]]};

(*s-out*)
Esout := {0, 1, 0};

(*Rotation matrices*)
Rotx[\[Phi]_] := {{1, 0, 0}, {0, Cos[\[Phi]], -Sin[\[Phi]]}, {0, 
    Sin[\[Phi]], Cos[\[Phi]]}};
Roty[\[Phi]_] := {{Cos[\[Phi]], 0, Sin[\[Phi]]}, {0, 1, 
    0}, {-Sin[\[Phi]], 0, Cos[\[Phi]]}};
Rotz[\[Phi]_] := {{Cos[\[Phi]], -Sin[\[Phi]], 0}, {Sin[\[Phi]], 
    Cos[\[Phi]], 0}, {0, 0, 1}};
Rot[\[Phi]_] := {{Cos[\[Phi]] + cx^2*(1 - Cos[\[Phi]]), 
    cx*cy*(1 - Cos[\[Phi]]) - cz*Sin[\[Phi]], 
    cx*cz*(1 - Cos[\[Phi]]) - 
     cy*Sin[\[Phi]]}, {cx*cy*(1 - Cos[\[Phi]]) + cz*Sin[\[Phi]], 
    Cos[\[Phi]] + cy^2*(1 - Cos[\[Phi]]), 
    cy*cz*(1 - Cos[\[Phi]]) - 
     cx*Sin[\[Phi]]}, {cx*cz*(1 - Cos[\[Phi]]) - cy*Sin[\[Phi]], 
    cy*cz*(1 - Cos[\[Phi]]) + cx*Sin[\[Phi]], 
    Cos[\[Phi]] + cz^2*(1 - Cos[\[Phi]])}};

\!\(\*
TagBox[
RowBox[{"(", "", GridBox[{
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"xxx"},
{"xxy"},
{"xxz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"xxy"},
{"xyy"},
{"xyz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"xxz"},
{"xyz"},
{"xzz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}]},
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"yxx"},
{"yxy"},
{"yxz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"yxy"},
{"yyy"},
{"yyz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"yxz"},
{"yyz"},
{"yzz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}]},
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"zxx"},
{"zxy"},
{"zxz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"zxy"},
{"zyy"},
{"zyz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"zxz"},
{"zyz"},
{"zzz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}]}
},
GridBoxAlignment->{
        "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
         "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}], "", ")"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\) := \!\(\*
TagBox[
RowBox[{"(", "", GridBox[{
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"0.1"},
{"0.5"},
{"0.1"}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"0.5"},
{"0.1"},
{"0.5"}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"0.1"},
{"0.5"},
{"0.1"}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}]},
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"0.1"},
{"0.11"},
{"0.1"}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"0.11"},
{"0.1"},
{"0.11"}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"0.1"},
{"0.11"},
{"0.1"}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}]},
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"0.14"},
{"0"},
{"0"}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"0"},
{"0.15"},
{"0"}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"0"},
{"0"},
{"0.16"}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}]}
},
GridBoxAlignment->{
    "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
     "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}], "", ")"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\);
chiC1 := \!\(\*
TagBox[
RowBox[{"(", "", GridBox[{
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"xxx"},
{"xxy"},
{"xxz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"xxy"},
{"xyy"},
{"xyz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"xxz"},
{"xyz"},
{"xzz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}]},
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"yxx"},
{"yxy"},
{"yxz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"yxy"},
{"yyy"},
{"yyz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"yxz"},
{"yyz"},
{"yzz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}]},
{
RowBox[{"(", "", 
TagBox[GridBox[{
{"zxx"},
{"zxy"},
{"zxz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"zxy"},
{"zyy"},
{"zyz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}], 
RowBox[{"(", "", 
TagBox[GridBox[{
{"zxz"},
{"zyz"},
{"zzz"}
},
GridBoxAlignment->{
             "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
              "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], "", ")"}]}
},
GridBoxAlignment->{
        "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
         "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}], "", ")"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\);

(*Rotating sample coordinate system*)
chiprimeC1[\[Phi]_] := 
  FullSimplify[
   Transpose[
    Rot[\[Phi]] . 
     Transpose[Rot[\[Phi]] . (chiC1 . Transpose[Rot[\[Phi]]])]]];

(*Components of outgoing polarization,p-in*)
PxPin[\[Theta]_, \[Phi]_] := 
  Sum[chiprimeC1[\[Phi]][[1, 
       i]][[j]] Epin[\[Theta]][[i]] Epin[\[Theta]][[j]], {i, 1, 
    3}, {j, 1, 3}];
PyPin[\[Theta]_, \[Phi]_] := 
  Sum[chiprimeC1[\[Phi]][[2, 
       i]][[j]] Epin[\[Theta]][[i]] Epin[\[Theta]][[j]], {i, 1, 
    3}, {j, 1, 3}];
PzPin[\[Theta]_, \[Phi]_] := 
  Sum[chiprimeC1[\[Phi]][[3, 
       i]][[j]] Epin[\[Theta]][[i]] Epin[\[Theta]][[j]], {i, 1, 
    3}, {j, 1, 3}];
(*Components of outgoing polarization,s-in*)
PxSin[\[Theta]_, \[Phi]_] := 
  Sum[chiprimeC1[\[Phi]][[1, 
       i]][[j]] Esin[\[Theta]][[i]] Esin[\[Theta]][[j]], {i, 1, 
    3}, {j, 1, 3}];
PySin[\[Theta]_, \[Phi]_] := 
  Sum[chiprimeC1[\[Phi]][[2, 
       i]][[j]] Esin[\[Theta]][[i]] Esin[\[Theta]][[j]], {i, 1, 
    3}, {j, 1, 3}];
PzSin[\[Theta]_, \[Phi]_] := 
  Sum[chiprimeC1[\[Phi]][[3, 
       i]][[j]] Esin[\[Theta]][[i]] Esin[\[Theta]][[j]], {i, 1, 
    3}, {j, 1, 3}];

(*Finding PinPout,PinSout,SinPout,and SinSout*)
pinpout[\[Theta]_, \[Phi]_] := 
  FullSimplify[(PxPin[\[Theta], \[Phi]]*
       Cos[\[Theta]])^2 + (PzPin[\[Theta], \[Phi]]*Sin[\[Theta]])^2];
pinsout[\[Theta]_, \[Phi]_] := FullSimplify[PyPin[\[Theta], \[Phi]]^2];
sinpout[\[Theta]_, \[Phi]_] := 
  FullSimplify[(PxSin[\[Theta], \[Phi]]*
       Cos[\[Theta]])^2 + (PzSin[\[Theta], \[Phi]]*Sin[\[Theta]])^2];
sinsout[\[Theta]_, \[Phi]_] := FullSimplify[PySin[\[Theta], \[Phi]]^2];

(*Finding PinPout,PinSout,SinPout,and SinSout*)
pinpout[\[Theta]_, \[Phi]_] := 
  FullSimplify[(PxPin[\[Theta], \[Phi]]*
       Cos[\[Theta]])^2 + (PzPin[\[Theta], \[Phi]]*Sin[\[Theta]])^2];

Ipinpout[\[Theta]_, \[Phi]_] := (1/2)*c*\[Epsilon]*
   pinpout[\[Theta], \[Phi]]^2;

(*Plotting the results as a function of \[Phi]*)
Manipulate[
 PolarPlot[Ipinpout[\[Theta], \[Phi]], {\[Phi], 0, 2 \[Pi]}, 
  PlotRange -> All, 
  PlotLabel -> Subscript[p, in] Subscript[p, out]], {\[Theta], 
  0, \[Pi]/2, \[Pi]/12, ControlType -> PopupMenu}]


enter image description here

Any Ideas?

$\endgroup$
8
  • 1
    $\begingroup$ Whenever I try to run the command with the plots, I get empty plots with the tensor in a place where I want the plots to be with Manipulate, it is best to test your code first outside manipulate to make sure it is first working ok. Then you can move it inside Manipulate. This way you know if it does not work, then it is due to issue with Manipulate. Did you do that first? To test it outside Manipulate, just use some made up test values (those are the ones that would have come from the control variables). $\endgroup$
    – Nasser
    Commented Jul 26, 2022 at 20:23
  • $\begingroup$ I ran the code previously with test values and worked perfectly, but I want to change the values so that the plots change with the manipulate function when I use the sliders. $\endgroup$
    – Yeknic
    Commented Jul 26, 2022 at 20:33
  • $\begingroup$ Please simplify the example. Show a single PolarPlot. Supply the complete code for the example to work so those trying to help can simply copy and paste it into Mathematica. As presented the code does not generate the plots you show. $\endgroup$
    – Jagra
    Commented Jul 27, 2022 at 1:05
  • $\begingroup$ The latest addition to your example appears to work. What doesn't it do that you need to do? $\endgroup$
    – Jagra
    Commented Jul 27, 2022 at 3:51
  • $\begingroup$ Additionally, I believe you should make the following lines of code as assignments rather than functions: c = 3*10^8; \[Epsilon] = 8.85*10^(-12); {cx, cy, cz} = {0, 0, 1}; Esout = {0, 1, 0}; $\endgroup$
    – Jagra
    Commented Jul 27, 2022 at 3:53

1 Answer 1

1
$\begingroup$

You'll get better response from the community it you post the minimal amount of code that you need to demonstrate your problem.

Let's start with your first four assignments:

Ipinpout
Ipinsout
Isinpout
Isinsout

You have defined these as variables not functions.
Even your updated example code appears to confuse the two.


Your Manipulate has key things out of its required order.

The code below - based on your single plot example - should give you a way forward ...

    Manipulate[
 Module[{c, \[Epsilon], cx, cy, cz, kin, kout, Epin, Esin, Epout, 
   Esout, Rotx, Roty, Rotz , Rot, chiC1, chiprimeC1, PxPin, PyPin, 
   PzPin, PxSin, PySin, PzSin, pinpout, pinsout, sinpout, sinsout, 
   Ipinpout},
  
  c = 3*10^8;(* c=
  speed of light *)
  \[Epsilon] = 8.85*10^(-12);(* \[Epsilon]=
  permittivity of free space *)
  
  (* <cx,cy,cz> = Axis of rotation (sum must equal 1, Ex Rotx = <1,0,
  0> or Rot= <1/2,1/2,Sqrt[2]/2>) \[Phi]=
  Rotation of sample with respect to
     the lab coordinate system \[Theta]=
  Angle of incindent light wave with incident surface *)
  
  {cx, cy, cz} = {0, 0, 1};
  
  kin[\[Theta]_]    := {-Sin[\[Theta]], 
    0, -Cos[\[Theta]]};(*Incoming wave vector*)
  
  kout[\[Theta]_]  := {Sin[\[Theta]], 0, 
    Cos[\[Theta]]};(*Outgoing wave vector*)
  
  Epin[\[Theta]_]  := {Cos[\[Theta]], 0, Sin[\[Theta]]}; (*p-in*)
  
  Esin[\[Theta]_]  := {0, 1, 0};(*s-in*)
  
  Epout[\[Theta]_] := {Cos[\[Theta]], 0, -Sin[\[Theta]]};(*p-out*)
  
  Esout = {0, 1, 0};(*s-out*)
  
  (*Rotation matrices*)
  
  Rotx[\[Phi]_] := {{1, 0, 0}, {0, Cos[\[Phi]], -Sin[\[Phi]]}, {0,  
     Sin[\[Phi]], Cos[\[Phi]]}}; 
  Roty[\[Phi]_] := {{Cos[\[Phi]], 0, Sin[\[Phi]]}, {0, 1, 
     0}, {-Sin[\[Phi]], 0, Cos[\[Phi]]}};
  Rotz[\[Phi]_] := {{Cos[\[Phi]], -Sin[\[Phi]], 0}, {Sin[\[Phi]], 
     Cos[\[Phi]], 0}, {0, 0, 1}};
  Rot[\[Phi]_]   := {
    {Cos[\[Phi]] + cx^2*(1 - Cos[\[Phi]]), 
     cx*cy*(1 - Cos[\[Phi]]) - cz*Sin[\[Phi]], 
     cx*cz*(1 - Cos[\[Phi]]) - cy*Sin[\[Phi]]}, 
    {cx*cy*(1 - Cos[\[Phi]]) + cz*Sin[\[Phi]], 
     Cos[\[Phi]] + cy^2*(1 - Cos[\[Phi]]), 
     cy*cz*(1 - Cos[\[Phi]]) - cx*Sin[\[Phi]]},
     {cx*cz*(1 - Cos[\[Phi]]) - cy*Sin[\[Phi]], 
     cy*cz*(1 - Cos[\[Phi]]) + cx*Sin[\[Phi]], 
     Cos[\[Phi]] + cz^2*(1 - Cos[\[Phi]])}};
  
  (*Rotating sample coordinate system*)
  
  chiprimeC1[\[Phi]_] := 
   FullSimplify[
    Transpose[  
     Rot[\[Phi]] . 
      Transpose[Rot[\[Phi]] . (chiC1 . Transpose[Rot[\[Phi]]])]]];
  
  (*Components of outgoing polarization,p-in*)
  
  PxPin[\[Theta]_, \[Phi]_] := 
   Sum[chiprimeC1[\[Phi]][[1, 
        i]][[j]] Epin[\[Theta]][[i]] Epin[\[Theta]][[j]], {i, 1, 
     3}, {j, 1, 3}];
  PyPin[\[Theta]_, \[Phi]_] := 
   Sum[chiprimeC1[\[Phi]][[2, 
        i]][[j]] Epin[\[Theta]][[i]] Epin[\[Theta]][[j]], {i, 1, 
     3}, {j, 1, 3}]; 
  PzPin[\[Theta]_, \[Phi]_] := 
   Sum[chiprimeC1[\[Phi]][[3, 
        i]][[j]] Epin[\[Theta]][[i]] Epin[\[Theta]][[j]], {i, 1, 
     3}, {j, 1, 3}];
  
  (*Components of outgoing polarization,s-in*)
  
  PxSin[\[Theta]_, \[Phi]_] := 
   Sum[chiprimeC1[\[Phi]][[1, 
        i]][[j]] Esin[\[Theta]][[i]] Esin[\[Theta]][[j]], {i, 1, 
     3}, {j, 1, 3}]; 
  PySin[\[Theta]_, \[Phi]_] := 
   Sum[chiprimeC1[\[Phi]][[2, 
        i]][[j]] Esin[\[Theta]][[i]] Esin[\[Theta]][[j]], {i, 1, 
     3}, {j, 1, 3}]; 
  PzSin[\[Theta]_, \[Phi]_] := 
   Sum[chiprimeC1[\[Phi]][[3, 
        i]][[j]] Esin[\[Theta]][[i]] Esin[\[Theta]][[j]], {i, 1, 
     3}, {j, 1, 3}];
  
  (*Finding PinPout,PinSout,SinPout,and SinSout*)
  
  pinpout[\[Theta]_, \[Phi]_] := 
   FullSimplify[(PxPin[\[Theta], \[Phi]]*
        Cos[\[Theta]])^2 + (PzPin[\[Theta], \[Phi]]*
        Sin[\[Theta]])^2];
  pinsout[\[Theta]_, \[Phi]_] := 
   FullSimplify[PyPin[\[Theta], \[Phi]]^2]; 
  sinpout[\[Theta]_, \[Phi]_] := 
   FullSimplify[(PxSin[\[Theta], \[Phi]]* 
        Cos[\[Theta]])^2 + (PzSin[\[Theta], \[Phi]]*Sin[\[Theta]])^2];
   sinsout[\[Theta]_, \[Phi]_] := 
   FullSimplify[PySin[\[Theta], \[Phi]]^2];
  
  Ipinpout[\[Theta]_, \[Phi]_] := (1/2)*c*\[Epsilon]*
    pinpout[\[Theta], \[Phi]]^2;
  chiC1 = \!\(\*
TagBox[
RowBox[{"(", GridBox[{
{
RowBox[{"(", 
TagBox[GridBox[{
{"xxx"},
{"xxy"},
{"xxz"}
},
GridBoxAlignment->{
              "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}], 
RowBox[{"(", 
TagBox[GridBox[{
{"xxy"},
{"xyy"},
{"xyz"}
},
GridBoxAlignment->{
              "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}], 
RowBox[{"(", 
TagBox[GridBox[{
{"xxz"},
{"xyz"},
{"xzz"}
},
GridBoxAlignment->{
              "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}]},
{
RowBox[{"(", 
TagBox[GridBox[{
{"yxx"},
{"yxy"},
{"yxz"}
},
GridBoxAlignment->{
              "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}], 
RowBox[{"(", 
TagBox[GridBox[{
{"yxy"},
{"yyy"},
{"yyz"}
},
GridBoxAlignment->{
              "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}], 
RowBox[{"(", 
TagBox[GridBox[{
{"yxz"},
{"yyz"},
{"yzz"}
},
GridBoxAlignment->{
              "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}]},
{
RowBox[{"(", 
TagBox[GridBox[{
{"zxx"},
{"zxy"},
{"zxz"}
},
GridBoxAlignment->{
              "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}], 
RowBox[{"(", 
TagBox[GridBox[{
{"zxy"},
{"zyy"},
{"zyz"}
},
GridBoxAlignment->{
              "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}], 
RowBox[{"(", 
TagBox[GridBox[{
{"zxz"},
{"zyz"},
{"zzz"}
},
GridBoxAlignment->{
              "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
               "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.5599999999999999]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}],
Column], ")"}]}
},
GridBoxAlignment->{
         "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, 
          "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]}, 
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}, "RowsIndexed" -> {}}], ")"}],
Function[BoxForm`e$, 
MatrixForm[BoxForm`e$]]]\) ;
  (*Plotting the results as a function of \[Phi]*)
  
  (* Manipulate[ *)
  
  PolarPlot[Ipinpout[\[Theta], \[Phi]], {\[Phi], 0, 2 \[Pi]},
   PlotRange -> All, 
   PlotLabel -> Subscript[p, in] Subscript[p, out]
   ]],
 
 (* Controls *)
  {\[Theta], 0, \[Pi]/2, \[Pi]/12, 
  ControlType -> PopupMenu},
 
 {{xxx, 0, "xxx"}, -1, 1, .1, Appearance -> "Labeled"},
 {{xxy, 0, "xxy"}, -1, 1, .1, Appearance -> "Labeled"},
 {{xxz, 0, "xxz"}, -1, 1, .1, Appearance -> "Labeled"},
 {{xyy, 0, "xyy"}, -1, 1, .1, Appearance -> "Labeled"},
 {{xyz, 0, "xyz"}, -1, 1, .1, Appearance -> "Labeled"},
 {{xzz, 0, "xzz"}, -1, 1, .1, Appearance -> "Labeled"},
 
 {{yxx, 0, "yxx"}, -1, 1, .1, Appearance -> "Labeled"},
 {{yxy, 0, "yxy"}, -1, 1, .1, Appearance -> "Labeled"},
 {{yxz, 0, "yxz"}, -1, 1, .1, Appearance -> "Labeled"},
 {{yyy, 0, "yyy"}, -1, 1, .1, Appearance -> "Labeled"},
 {{yyz, 0, "yyz"}, -1, 1, .1, Appearance -> "Labeled"},
 {{yzz, 0, "yzz"}, -1, 1, .1, Appearance -> "Labeled"},
 
 {{zxx, 0, "zxx"}, -1, 1, .1, Appearance -> "Labeled"},
 {{zxy, 0, "zxy"}, -1, 1, .1, Appearance -> "Labeled"},
 {{zxz, 0, "zxz"}, -1, 1, .1, Appearance -> "Labeled"},
 {{zyy, 0, "zyy"}, -1, 1, .1, Appearance -> "Labeled"},
 {{zyz, 0, "zyz"}, -1, 1, .1, Appearance -> "Labeled"},
 {{zzz, 0, "zzz"}, -1, 1, .1, Appearance -> "Labeled"}
 ]

enter image description here

The key idea follows from allowing the controls of the Manipulate to dynamically reassign values to the individual elements of the tensor(s).

$\endgroup$
4
  • $\begingroup$ What I want to accomplish with this code is to change the values so that the plots change with the manipulate function when I use the sliders. These are the tensor elements (xxx, xxy, xxz... etc.) and theta. I defined the equations in terms of their most general form with theta, the tensor elements, and phi. What is plotted is the assignments as a function of phi, with being able to change the angle theta and tensor elements $\endgroup$
    – Yeknic
    Commented Jul 26, 2022 at 23:59
  • $\begingroup$ To add to the prevoius comment, chiC1 is the element of the tensor that I would manipulate, ranging from -1 to 1 on intervals of 0.1. $\endgroup$
    – Yeknic
    Commented Jul 27, 2022 at 0:05
  • $\begingroup$ To add one last thing, what I am trying to do is to manipulate the tensor elements and theta angle, run the equations for the plots with the manipulated elements, then plot those equations as a function of phi $\endgroup$
    – Yeknic
    Commented Jul 27, 2022 at 0:09
  • $\begingroup$ @Xenconic -- please add code and an example to you original post that shows a single set of tensor elements plotted as you want to see it by the PolarPlot. $\endgroup$
    – Jagra
    Commented Jul 27, 2022 at 0:18

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.