1
$\begingroup$

Good Evening,

I defined a function which is composed of other several functions. Mathematica compiles well but I can't get a plot and I do not understand way.

Can anyone help me with the code and explaining me why nothing is showed on the plot?

Thanks in advance

f1 = 0.0;
f2 = 0.0;
f3 = -9.0; (*fN*)
T = 300;(*K*)
ν = 1.002; (*(fN*s )/μm^2*)

Subscript[r, 0] = 0.5;(*μm*)
Subscript[r, 2] = 0.8;(*μm*)

Subscript[r, 1] = 0.2;(*μm*)

Subscript[γ, 0] = 6 π ν Subscript[r, 0];
Subscript[γ, 2] = 6 π ν Subscript[r, 2]
Subscript[γ, 1] = 6 π ν Subscript[r, 1]
(* 15.1098 *)
(* 3.77745 *)

ϕ1 = π/3;
ϕ2 = π/4;


V1[Tkin_] := (1/Subscript[γ, 1])[
   f2 - f3 (((Tkin - T)/T) Cos[θ] Sin[θ])/(
     Subscript[γ, 1]/Subscript[γ, 
      0] + ((Tkin - T)/T) (Sin[θ])^2)];
V2[Tkin_] := (1/Subscript[γ, 2])[
   f2 - f3 (((Tkin - T)/T) Cos[θ] Sin[θ])/(
     Subscript[γ, 2]/Subscript[γ, 
      0] + ((Tkin - T)/T) (Sin[θ])^2)];


V11 = V1[Tkin1]; (* Velocity of the 1st particle in protocol 1*)
V21 =
  V2[Tkin1]; (* Velocity of the 2nd particle in protocol 1*)


V12 = V1[Tkin2]; (* Velocity of the 1st particle in protocol 2*)

V22 = V2[Tkin2]; (* Velocity of the 2nd particle in protocol 2*)

VA[Tkin1_, 
   Tkin2_, ϕ1_, ϕ2_] := {{V11 Sin[ϕ1] - 
     V12 Sin[ϕ2], V11 Cos[ϕ1] + V12 Cos[ϕ2]}};
VB[Tkin1_, 
   Tkin2_, ϕ1_, ϕ2_] := {{V21 Sin[ϕ1] - 
     V22 Sin[ϕ2], V21 Cos[ϕ1] - V22 Cos[ϕ2]}};

VAA = VA[Tkin1, Tkin2, ϕ1, ϕ2];
VBB = VB[Tkin1, Tkin2, ϕ1, ϕ2];

delta[Tkin1_, Tkin2_] = 
  ArcCos[VAA.Transpose[VBB]/(Norm[VAA] Norm[VBB])];
Plot3D[delta, {Tkin1, 300, 1000}, {Tkin2, 300, 1000}, 
 AxesLabel -> {"Tkin1", "Tkin2", "γ"}, 
 ColorFunction -> "BrownCyanTones", PlotRange -> Automatic]
$\endgroup$
  • 1
    $\begingroup$ You should avoid using Subscript while defining symbols (variables). Subscript[x, 1] is not a symbol, but a compound expression where Subscript is an operator without built-in meaning. You expect to do $x_1=2$ but you are actually doing Set[Subscript[x, 1], 2] which is to assign a Downvalue to the oprator Subscript and not an Ownvalue to an indexed x as you may intend. Read how to properly define indexed variables here $\endgroup$ – rhermans May 25 '17 at 17:44
  • $\begingroup$ There are many errors in your code. You should start by testing something simpler first. if delta is a function, then it should be called with parameters. [theta] is not defined $\endgroup$ – rhermans May 25 '17 at 17:49
  • 2
    $\begingroup$ To expand on rherman's comment. Mathematica is a front end for a programming language. You shouldn't be trying to make everything pretty when you don't know how to do it safely. γ1 is just as useful as Subscript[γ, 1] $\endgroup$ – Feyre May 25 '17 at 17:50
6
$\begingroup$

The code does not run properly due many simple issues. First, we cannot use brackets and braces in the function definitions because Mathematica will comprehend differently from conventional math. Secondly, the functions V11,V12,V21 and V22 can be neglected and just use V1 and V2 with the proper Tkin variable. The functions VAA and VBB can be erased because VA and VB have the same definition. Ultimately, the angle $\theta$ needs a value.

f1 = 0.0;
f2 = 0.0;
f3 = -9.0;       (*fN*)
T = 300;         (*K*)
\[Nu] = 1.002;   (*(fN*s)/\[Mu]m^2*)

r[0] = 0.5;      (*\[Mu]m*)
r[1] = 0.2;      (*\[Mu]m*)
r[2] = 0.8;      (*\[Mu]m*)

\[Gamma][0] = 6 \[Pi] \[Nu] r[0];  
\[Gamma][1] = 6 \[Pi] \[Nu] r[1];
\[Gamma][2] = 6 \[Pi] \[Nu] r[2];

(*15.1098*)
(*3.77745*)


\[Theta] = 3.14;


V1[x_] := (1/\[Gamma][1]) (f2 - 
     f3 (((x - T)/T) Cos[\[Theta]] Sin[\[Theta]])/(\[Gamma][
           1]/\[Gamma][0] + ((x - T)/T) (Sin[\[Theta]])^2));
V2[y_] := (1/\[Gamma][2]) (f2 - 
     f3 (((y - T)/T) Cos[\[Theta]] Sin[\[Theta]])/(\[Gamma][
           2]/\[Gamma][0] + ((y - T)/T) (Sin[\[Theta]])^2));



VA[Tkin1_, 
   Tkin2_, \[Phi]1_, \[Phi]2_] := {{V1[Tkin1] Sin[\[Phi]1] - 
     V1 [Tkin2] Sin[\[Phi]2], 
    V1[Tkin1] Cos[\[Phi]1] + V1[Tkin2] Cos[\[Phi]2]}};
VB[Tkin1_, 
   Tkin2_, \[Phi]1_, \[Phi]2_] := {{V2[Tkin1] Sin[\[Phi]1] - 
     V2[Tkin2] Sin[\[Phi]2], 
    V2[Tkin1] Cos[\[Phi]1] - V2[Tkin2] Cos[\[Phi]2]}};

delta[Tkin1_, Tkin2_, \[Phi]1_, \[Phi]2_] := 
  ArcCos[(VA[Tkin1, Tkin2, \[Phi]1, \[Phi]2].Transpose[
       VB[Tkin1, Tkin2, \[Phi]1, \[Phi]2]])/(Norm[
       VA[Tkin1, Tkin2, \[Phi]1, \[Phi]2]] Norm[
       VB[Tkin1, Tkin2, \[Phi]1, \[Phi]2]])];

\[Phi]1 = \[Pi]/3;
\[Phi]2 = \[Pi]/4;



Plot3D[delta[Tkin1, Tkin2, \[Phi]1, \[Phi]2], {Tkin1, 300, 
  1000}, {Tkin2, 300, 1000}, 
 AxesLabel -> {"Tkin1", "Tkin2", "\[Gamma]"}, 
 ColorFunction -> "BrownCyanTones", PlotRange -> Automatic]

The plot of the angle $\Delta$ will be

enter image description here

Surely this code can be improved in order to get a more elegant and fine working algorithm.

| improve this answer | |
$\endgroup$

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.