Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
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}]][[2]];
  complex[x_] := LPL /. sol[[2]] /. 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?

share|improve this question
    
The solution is complex at places –  Sjoerd C. de Vries Nov 8 '12 at 20:09
2  
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
add comment

1 Answer 1

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}]

Manipulate[] interface

I use Re to plot only the real part of complex. I noticed that it also has an imaginary part with very small magnitude.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.