0

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

2 Answers2

4

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

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

enter image description here

b.gates.you.know.what
  • 20,103
  • 2
  • 43
  • 84
ybeltukov
  • 43,673
  • 5
  • 108
  • 212
4

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

Michael E2
  • 235,386
  • 17
  • 334
  • 747