1

I'm solving two (1-parameter) differential equations and I want to plot the product of their solutions, how do I do this? Here's the code,

Deter[p0_] := Module[{p = p0},
M = 1; m = 1; q = 1; Q = √3; d = 3; L = 1; ω = 0;

cutoff = 0.0001 ;
f[u_] = 1 - M u^(-d);
vneg[u_] = (1/√f[u]) (ω + Q q (1 - u^(2 - d))) - Q p u^(2 - d); 
vpls[u_] = (1/√f[u]) (ω + Q q (1 - u^(2 - d))) + Q p u^(2 - d);

FlowPlus[u_] = (-y[u] 2 m L u + vneg[u] - 
  k + (vpls[u] + k) y[u]^2)/(u^2  √f[u])  ;
FlowNeg[u_] = (-z[u] 2 m L u + vneg[u] + 
  k + (vpls[u] - k) z[u]^2)/(u^2  √f[u])  ;

solPlus = ParametricNDSolveValue[{y'[u] == FlowPlus[u], y[1 + cutoff]== I},
           y, {u, 1 + cutoff, 1/cutoff}, {k}];
solNeg = ParametricNDSolveValue[{z'[u] == FlowNeg[u], z[1 + cutoff] == I}, 
           z, {u, 1 + cutoff, 1/cutoff}, {k}];

Return[{solPlus, solNeg}]

]

What I want to plot is (but I'm getting a blank plot only)

Plot[Evaluate[Re[Deter[8][[1]][k][1/cutoff]] Re[Deter[8][[2]][k][1/cutoff]] ], {k, -5, 5},
     PlotRange -> Automatic, AxesOrigin -> {0, 0}] 

Thanks!

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Skylar15
  • 281
  • 1
  • 9
  • Thank you for fixing the code. I amended my answer accordingly. Is the plot I obtained what you might have expected? – MarcoB Jun 01 '15 at 16:19

1 Answers1

1

As I see it, your Deter expressions are not evaluated as you expected, leaving them as non-numerical values.

Using your definition of Deter, and forcing evaluation of the Plot argument using the undocumented but well-established Evaluated -> True option:

Plot[
 Times @@ Re[Through[Through[Deter[8][k]][1/cutoff]]],
 {k, -5, 5},
 Evaluated -> True
]

I obtain this:

Mathematica graphics

See e.g. this answer from Mr. Wizard regarding the preferred use of Evaluated -> True over explicitly wrapping the arguments of Plot and the like inside an Evaluate: Recommended form for evaluation.

MarcoB
  • 67,153
  • 18
  • 91
  • 189
  • Thanks! Please note the edits I made. I some how forgot the Re[] part in the Plot line, but when I use your code with either Return[{Re[solPlus], Re[solNeg]}] or by keeping the same Return and making .. Chop[Through[Through[Re[Deter[8][k]]][1/cutoff]]] .. I don't get any output. Can you please comment. – Skylar15 Jun 01 '15 at 16:20
  • @Skylar15 Please take a look at the code I just posted. The Re function needs to be the outermost one in the Through cascade. – MarcoB Jun 01 '15 at 16:21
  • Oh yes.. I's just trying that. Thanks! – Skylar15 Jun 01 '15 at 16:22
  • @Skylar15 No problem, glad it helped! – MarcoB Jun 01 '15 at 16:23
  • Sorry one more thing.. I'm wondering why are there two plots! In my Plot in the question I should get one plot which is a product of two solutions. – Skylar15 Jun 01 '15 at 16:28
  • @Skylar15 you are quite right. I was working on each solution separately first, with the intention of plotting the product when I got them working, but forgot to multiply them at the end! See edit. – MarcoB Jun 01 '15 at 16:31
  • No problem. This is perfect. Thanks again! – Skylar15 Jun 01 '15 at 16:33