0
$\begingroup$

I'm trying to plot solution of system of equations as a function of parameter

Manipulate[{
  Quiet[sol = Solve[{Ka*P*L*L == PLL, P0 == P + PLL, r*P0 == L + 2*PLL}, {P, L, PLL}]][[3]];
  complex[x_] := PLL /. sol[[3]] /. r -> x;
  Plot[{
     Hold[Evaluate@D[complex[r], r]],
     Hold[Evaluate@D[-complex[r], {r, 2}]]
     } // Release,
   {r, 0.1, 4},
   PlotStyle -> {Red, Blue}
   ]},
 {Ka, 10000, 10000},
 {P0, 0.5, 1}
 ]

My plot has gaps! Why and how I can eliminate them?

enter image description here

$\endgroup$
4
$\begingroup$

Thre is a small imaginary part due to numerical errors. Just add Re inside Evaluate:

... Evaluate@Re@D[...] ...

enter image description here

$\endgroup$
4
$\begingroup$

One way, which I would favor, is to use Chop to remove small imaginary parts. (I would favor this in the case that large imaginary parts should not be ignored, but indicate that the actual solution is not real.)

Manipulate[
 With[{sol = 
    Quiet[Solve[{Ka*P*L*L == PLL, P0 == P + PLL, r*P0 == L + 2*PLL}, {P, L, PLL}]][[3]]},
  With[{df = D[PLL /. sol, r], d2f = D[PLL /. sol, {r, 2}]},
   Plot[{Chop[df], Chop[-d2f]}, {r, 0.1, 4}, 
    PlotStyle -> {Red, Blue}]
   ]],
 {Ka, 10000, 10000}, {P0, 0.5, 1}]

Mathematica graphics

$\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.