1
$\begingroup$

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!

$\endgroup$
  • $\begingroup$ Thank you for fixing the code. I amended my answer accordingly. Is the plot I obtained what you might have expected? $\endgroup$ – MarcoB Jun 1 '15 at 16:19
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Skylar15 Jun 1 '15 at 16:20
  • $\begingroup$ @Skylar15 Please take a look at the code I just posted. The Re function needs to be the outermost one in the Through cascade. $\endgroup$ – MarcoB Jun 1 '15 at 16:21
  • $\begingroup$ Oh yes.. I's just trying that. Thanks! $\endgroup$ – Skylar15 Jun 1 '15 at 16:22
  • $\begingroup$ @Skylar15 No problem, glad it helped! $\endgroup$ – MarcoB Jun 1 '15 at 16:23
  • $\begingroup$ 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. $\endgroup$ – Skylar15 Jun 1 '15 at 16:28

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.