Message Boards Message Boards

0
|
4770 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

ParametricPlot of multiple ODEs only displays 1 PlotLegend instead of all

Posted 10 years ago
Hey there,
I'm quite new to Mathematica, but am required to use it by university. Anyways.
The topic actually says it all. I try to get a parametric plot, which works just fine. But Mathematica does not label my functions completely (and the one label that is applied was applied to the wrong function, 1 MeV is supposed to be the blue one).
Here's the Code:
 solution[energy_] :=
 
   NDSolve[{2 (z*e^2)/(r*(x[t]^2 + y[t]^2)^(3/2))*x[t] == m*x''[t],
 
     2 (z*e^2)/(r*(x[t]^2 + y[t]^2)^(3/2))*y[t] == m*y''[t], y[0] == p,
 
      y'[0] == 0, x'[0] == v[energy], x[0] == a}, {x, y}, {t, 0, max}];
 sol = {solution[1], solution[10 ], solution[50]};
 
ParametricPlot[

{

  {Evaluate[{x[t], y[t]}  /. sol[[1]]]},

  {Evaluate[{x[t], y[t]}  /. sol[[2]]]},

  {Evaluate[{x[t], y[t]}  /. sol[[3]]]}

  }, {t, 0, max}, PlotRange -> {-5*10^-12, 5*10^-12},

AxesLabel -> {"x[t]", "y[t]"},

PlotLegends -> {"1 MeV", "10 MeV", "50 MeV"}, ImageSize -> Large]

Also on a side note:
Is it possible to directly use solution in parametric plot without using the workaround with sol ={..} ? I'd like to use a manipulate plot with it. emoticon
Edit:
Is it possible to scale the x and y axis in a Parametric Plot differently?

Next Edit:
When I se PlotLegend->"Expressions" it seems to write everything in one line
I managed to workarond it using PlotLegends->SwatchLegends
Attachments:
POSTED BY: d n
2 Replies
Posted 10 years ago
Here's the file and code:
  (* Konstanten *)
  
  m = 4*1.672621777*10^-27;(* Masse Alpha-Teilchen *)
  
  e = 1.60218 * 10^-19  ; (* Elementarladung *)
  
  z = 79 ;(* Ordnungszahl Gold *)
  
  r = 4*Pi*8.854*10^-12; (* 4 Pi Epsilon Null *)
 
 (* Variablen *)
 
 p[k_] := k*10^-14; (* Stoßparameter *)
 
 a = -1 * 10^-10; (* Abstand vom Atom *)
 
 v[energy_] := Sqrt[
 
   2*energy*10^6 * e /
 
    m]; (* Geschwindigkeit, Abhänging von Energie in MeV *)
 
 max = 10^-15; (* maximale Zeit zu der berechnet wird *)
 
 
 
 (* Numerisches Lösen der DGL *)
 
 solution[energy_, k_] :=
 
   NDSolve[{2 (z*e^2)/(r*(x[t]^2 + y[t]^2)^(3/2))*x[t] == m*x''[t],
 
     2 (z*e^2)/(r*(x[t]^2 + y[t]^2)^(3/2))*y[t] == m*y''[t],
 
     y[0] == p[k], y'[0] == 0, x'[0] == v[energy], x[0] == a}, {x,
 
     y}, {t, 0, max}];
 
 
 
 
 
 
 
 
 
 sol1 = {solution[1, 1], solution[10, 1], solution[50, 1]};
 
 sol5 = {solution[1, 5], solution[10, 5], solution[50, 5]};
 
 sol10 = {solution[1, 10], solution[10, 10], solution[50, 10]};
 
 
 
 
 
 
 
 (* Plot für p = 10fm *)
 
 ParametricPlot[
 
  {
 
   {Evaluate[{x[t], y[t]}  /. sol1[[1]]]},
 
   {Evaluate[{x[t], y[t]}  /. sol1[[2]]]},
 
   {Evaluate[{x[t], y[t]}  /. sol1[[3]]]}
 
   }, {t, 0, max}, PlotRange -> {-5*10^-12, 5*10^-12},
 
  AxesLabel -> {"x[t]", "y[t]"}, ImageSize -> Large,
 
  PlotStyle -> {Blue, Red, Green},
 
  PlotLegends ->
 
   SwatchLegend[{Blue, Red, Green}, {"1 MeV", "10 MeV", "50 MeV"}],
 
  PlotLabel -> Style["p = 10fm", FontSize -> 18]]
 
 (* Plot für 50fm *)
 
 ParametricPlot[
 
  {
 
   {Evaluate[{x[t], y[t]}  /. sol5[[1]]]},
 
   {Evaluate[{x[t], y[t]}  /. sol5[[2]]]},
 
   {Evaluate[{x[t], y[t]}  /. sol5[[3]]]}
 
   }, {t, 0, max}, PlotRange -> {-5*10^-12, 5*10^-12},
 
  AxesLabel -> {"x[t]", "y[t]"}, ImageSize -> Large,
 
  PlotStyle -> {Blue, Red, Green},

PlotLegends ->

  SwatchLegend[{Blue, Red, Green}, {"1 MeV", "10 MeV", "50 MeV"}],

PlotLabel -> Style["p = 50fm", FontSize -> 18]]

(*Plot für 100fm*)

ParametricPlot[

{

  {Evaluate[{x[t], y[t]}  /. sol10[[1]]]},

  {Evaluate[{x[t], y[t]}  /. sol10[[2]]]},

  {Evaluate[{x[t], y[t]}  /. sol10[[3]]]}

  }, {t, 0, max}, PlotRange -> {-5*10^-12, 5*10^-12},

AxesLabel -> {"x[t]", "y[t]"}, ImageSize -> Large,

PlotStyle -> {Blue, Red, Green},

PlotLegends ->

  SwatchLegend[{Blue, Red, Green}, {"1 MeV", "10 MeV", "50 MeV"}],

PlotLabel -> Style["p = 100fm", FontSize -> 18]]
Attachments:
POSTED BY: d n
what is your max value.. and what are the parameter values?

you can just upload nb code, intead of copying and pasting..
POSTED BY: selahittin cinar
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract