Gaps at curve that represents the solution of system of equations as a function of parameter

Manipulate[{
Quiet[sol =
Solve[{K1*P*L == PL, K2*P*L == LP, K3*PL*L == LPL,
P0 == P + PL + LP + LPL, r*P0 == L + PL + LP + 2*LPL}, {P, L,
LP, PL, LPL}]][];
complex[x_] := LPL /. sol[] /. r -> x;
Plot[{complex[r]}, {r, 0.1, 6}]
},

{K1, 1001, 10000},
{K2, 1000, 10000},
{K3, 1000, 10000},
{P0, 0.1, 1}
]

If K1 == K2 == K3 we have nice curve otherwise there are gaps at curve. what's wrong?

• The solution is complex at places – Sjoerd C. de Vries Nov 8 '12 at 20:09
• Better also add TrackedSymbols -> {K1, K2, K3, P0} to prevent your Manipulatefrom being busy all the time. – Sjoerd C. de Vries Nov 8 '12 at 20:15
• Related: (17202), (58976), (65084), (69976) – Mr.Wizard Feb 19 '15 at 20:56

Try!

(*First solve and store the symbolic data*)
val = LPL /.First@Solve[{K1*P*L == PL, K2*P*L == LP, K3*PL*L == LPL,
P0 == P + PL + LP + LPL, r*P0 == L + PL + LP + 2*LPL}, {P, L,LP, PL, LPL}];
(*
+ Define a function that evaluates the symbolic expression given
numerical value to the parameters.
+ We use DifInd with default value 0 we can compute the d-th derivative in
case of DifInd=d.
*)
complex[rVal_, K1Val_, K2Val_, K3Val_, P0Val_, DifInd_: 0] :=
Re@With[{r = rVal, K1 = K1Val, K2 = K2Val, K3 = K3Val, P0 = P0Val,
índex = DifInd}, (Evaluate@D[val, {r, índex}])];
Needs["PlotLegends`"];
Manipulate[Plot[Evaluate[{
complex[r, K1, K2, K3, P0],
complex[r, K1, K2, K3, P0, 1],
complex[r, K1, K2, K3, P0, 4]
}], {r, 0.1, 6},
ImageSize -> 600,
Frame -> True,
PlotStyle -> {Thick, {Red, Thick, Dashed}, Green},
PlotLegend -> {"f(x)", "f'(x)", "f''''(x)"},
LegendPosition -> {1.1, -0.4}],
{K1, 1001, 10000}, {K2, 1000,10000}, {K3, 1000, 10000}, {P0, 0.1, 1}] I use Re to plot only the real part of complex. I noticed that it also has an imaginary part with very small magnitude.

• Cool! Thank you! I tried to plot as well derivative of complex using following code: Plot[{Evaluate[complex[r, K1, K2, K3, P0]], Hold[Evaluate@D[complex[r, K1, K2, K3, P0], r]]} // Release, {r, 0.1, 6}] without success. I'm still a newbie in mathematica, so I will be happy if you help me one more time. – user4545 Nov 9 '12 at 18:45
• @Philipp Here comes the help for one more time! I updated the answer to accommodate derivatives with in the definition of complex. You need to change the definition of the function itself. You cant perform the D[] inside Plot as complexwas previously defined not be symbolic but only numeric inside Plot. – PlatoManiac Nov 9 '12 at 20:23