0
$\begingroup$

I have a problem that is somewhat related to this https://stackoverflow.com/questions/7727668/putting-two-plots-in-a-manipulate-whilst-keeping-the-plots-visible but I would like to plot two functions in one plot.

 Clear[x, μ, ξ, β, γ, rp, sp, λCrp, λCsp , λlower];
 Clear[ c, yp, λ, α, ϵp, ηp, ep];
 rp = ϵp*λ + (1 - ηp)*(1 - λ);
 sp = ηp*(1 - λ) + (1 - ϵp)*λ;
 λCrp = (ϵp*λ)/(ϵp*λ + (1 - ηp)*(1 - λ));
 λCsp = (ηp*(1 - λ))/(ηp*(1 - λ) + (1 - ϵp)*λ);

 (* Two Functions *)
 λlower = λ /. Solve[rp*(yp - ep - c + α*λCrp) + sp*(yp - ep + α*(1 - λCsp)) == yp + α*(1 - λ), {λ}]
 λupper =λ /. Solve[rp*(yp - ep - c + α*λCrp) + sp*(yp - ep + α*(1 - λCsp)) == yp + α*(1 - λ), {λ}]

 (* Properties - Visualization of Values for λlower *)
 Manipulate[λ /. Solve[rp*(yp - ep - c + α*λCrp) + sp*(yp - ep + α*(1 - λCsp)) == yp + α*(1 - λ), {λ}], {ep, 0, α}, {c, 0, α}, {α, 0, 1}, {ϵp, 0.5, 1}, {ηp, 0.5, 1}]
 Manipulate[Plot[λ /. Solve[rp*(yp - ep - c + α*λCrp) + sp*(yp - ep + α*(1 - λCsp)) == yp + α*(1 - λ), {λ}], {λ, 0,1}], {ep, 0, α}, {c, 0, α}, {α, 0, 1}, {ϵp, 0.5, 1}, {ηp, 0.5, 1}]

 (* Properties - Visualization of Both Values in One Plot *)
 (* Not working for both - λlower, λupper *)
 Manipulate[Plot[{Evaluate[λ /. Solve[Rationalize[rp (yp - ep - c + α λCrp) + 
      sp (yp - ep + α(1 - λCsp)) ==  yp + α(1 - λ)], {λ}][[1]] /. {ϵp -> ϵpa, ηp -> ηpa}], {λ, 0, 1}},{Evaluate[λ /. Solve[Rationalize[rp (yp - ep - c + α λCrp) + 
      sp (yp - ep + α(1 - λCsp)) ==  yp + αλ - c], {λ}][[1]] /. {ϵp -> ϵpa, ηp -> ηpa}], {λ, 0, 1}}], {ep, 0, α}, {c, 0, α}, {α, 0,1}, {ϵpa, 1/2, 1}, {ηpa, 1/2, 1}]          

The code does not work and therefore I do not know if there would be different colors assigned by default. If not, can I specify the color for each function?

Thank you!

$\endgroup$
7
  • $\begingroup$ Your code has unmatched brackets/parenthesis/whatever. Please copy it to your notebook, fix it and edit your question. Thanks $\endgroup$ Commented Nov 13, 2014 at 3:12
  • $\begingroup$ One ")" too much. Fixed it. $\endgroup$
    – Tom
    Commented Nov 13, 2014 at 16:58
  • $\begingroup$ Why does λlower === λlower gives True? $\endgroup$
    – Öskå
    Commented Nov 13, 2014 at 17:02
  • $\begingroup$ What is ep? There are way too many mistakes, please start with a smaller example. $\endgroup$
    – Öskå
    Commented Nov 13, 2014 at 17:15
  • $\begingroup$ ep is a variable. The question is an extension to an earlier discussion mathematica.stackexchange.com/questions/65449/… The part that is not working is on the bottom - plotting both functions into one plot. The last three lines starting with "Manipulate[Plot[{Evaluate[λ /. Solve[Rationalize[..." $\endgroup$
    – Tom
    Commented Nov 13, 2014 at 17:20

1 Answer 1

3
$\begingroup$

One thing I'd suggest is do not put Solve inside Manipulate if you don't really need to. In this case the expressions can be easily solved symbolically beforehand. Also you should specify initial values for your parameters so that you don't throw an error on first evaluation:

These now work fine.

 Clear[r1]
 r1[ep_, α_, ηp_, c_, ϵp_] = λ /. 
       First@Solve[rp*(yp - ep - c + α*λCrp) +
       sp*(yp - ep + α*(1 - λCsp)) == 
       yp + α*(1 - λ), {λ}];
 Manipulate[r1[ep, α, ηp, c, ϵp],
    {{ep, 0}, 0, α}, {{c, 0}, 0, α}, {{α, 1/2}, 0, 1}, 
    {{ϵp, .75}, 0.5, 1}, {{ηp, .5}, 0.5, 1}]
 Manipulate[
     Plot[r1[ep, α, ηp, c, ϵp], {λ, 0, 1}],
       {{ep, 0}, 0, α}, {{c, 0}, 0, α}, {{α, 1/2}, 0, 1}, 
       {{ϵp, .75}, 0.5, 1}, {{ηp, .5}, 0.5, 1}]

Note your plot is rather uninteresting since you have solved for Lambda, r1 always has a constant value..

In your last case you have additionally used incorrect syntax for plotting multiple functions. You should do

 Plot[  { f1[lambda],f2[lambda] } , {lambda,0,1 } ]

or

 Show[{ Plot[f1[lambda],{lambda,0,1 }],Plot[f2[lambda],{lambda,0,1 }]}]

not

 Plot[  { f1[lambda],{lambda,0,1 } } ,{ f2[lambda]  ,{lambda,0,1 }}  ]
$\endgroup$
3
  • $\begingroup$ Thank you! Could you clarify the role of {ep, 0}, {c, 0}, {[Alpha], 1/2}, {[Epsilon]p, .75}, {[Eta]p, .5} - are these additional assumptions (0,0,1/2,3/4,1/2) about the value range or plotting values? $\endgroup$
    – Tom
    Commented Nov 13, 2014 at 20:35
  • $\begingroup$ They are just initial values. Anything in the parameter range works ( I picked some numbers that avoid a divide by zero error at the start ) $\endgroup$
    – george2079
    Commented Nov 13, 2014 at 20:53
  • $\begingroup$ Got it and fixed the axis. I can track now how the ranges between the thresholds change. Thanks! $\endgroup$
    – Tom
    Commented Nov 13, 2014 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.