1
$\begingroup$

I'm trying to build a function that generate a string of restrictons to pass on to a region plot with ToExpression, but I think it fails to pass the plot variables.

Clear["Global`*"]
ClearAll[Subscript]
lb1[ps_, pr_] := (Sqrt[1 - ps] + Sqrt[pr - ps])^2/(1 - pr);
lb2[ps_, pr_] := (Sqrt[1 - ps] - Sqrt[pr - ps])^2/(1 - pr);
An[ps_, pr_, bb_,n_] := ((pr - ps)*(1 + lb2[ps, pr]^n) + 2 bb*(1 - lb2[ps, pr]^n))/(2*(pr - ps)*(lb1[ps, pr]^n -lb2[ps, pr]^n));

xp[ps_, pr_, bb_] := 1/2 - bb/(pr - ps);
xn[ps_, pr_, bb_, n_, c_] :=An[ps, pr, bb, n]*(lb1[ps, pr]^c - lb2[ps, pr]^c)+ xp[ps, pr, bb]*(1 - lb2[ps, pr]^c);
sfixed[n_, c_] := FullSimplify[xn[ps, pr, bb, n, c]];
sol[s_, r_, bu_, n_, c_] :=sfixed[n, c] /. {ps -> s, pr -> r, bb -> bu};
ordres[n_] :=Module[{i, x}, x = StringForm["0<sol[s,r,b,``,1]&&", n];Do[x = ToString[x] <>ToString[StringForm["sol[s,r,b,``,``]<sol[s,r,b,``,``]&&", n, i-1, n,i]], {i, 2, n - 1}]; x = ToString[x]<>ToString[StringForm["sol[s,r,b,``,``]<1", n, n - 1]]];

The function ordres should generate the restriction for n points. Here I fail to make the plot for n=2.

Manipulate[RegionPlot[{ToExpression[ordres[2]]}, {r, 0, 1}, {b, 0, 0.2}, WorkingPrecision -> 1000], {s, 0.8, 1}]

This is what I expect to get

Manipulate[RegionPlot[{{sol[s, r, b, 2, 1] > 0 && sol[s, r, b, 2, 1] < 1}}, {r,0, 1}, {b, 0, 0.2}, WorkingPrecision -> 1000], {s, 0.8, 1}]
$\endgroup$
  • 1
    $\begingroup$ try Manipulate[ RegionPlot[ToExpression[ordres[2]] /. s -> t, {r, 0, 1}, {b, 0, 0.2}, WorkingPrecision -> 1000], {t, 0.8, 1}]? $\endgroup$ – kglr Aug 13 at 16:30
0
$\begingroup$

Another option:

ordres2[n_, var_] := 
 Module[{i, x}, x = StringForm["0<sol[``,r,b,``,1]&&", var, n]; 
  Do[x = ToString[x] <> ToString[StringForm["sol[``,r,b,``,``]<sol[``,r,b,``,``]&&", var, n, 
       i - 1, var, n, i]], {i, 2, n - 1}]; 
  x = ToString[x] <> ToString[StringForm["sol[``,r,b,``,``]<1", var, n, n - 1]]]

Manipulate[
 RegionPlot[ToExpression[ordres2[2, t]], {r, 0, 1}, {b, 0, 0.2}, 
  WorkingPrecision -> 1000], {t, 0.8, 1}]
```
$\endgroup$
1
$\begingroup$

The issue is solved by the suggestion of kglr:

Manipulate[ RegionPlot[ToExpression[ordres[2]] /. s -> t, {r, 0, 1}, {b, 0, 0.2}, WorkingPrecision -> 1000], {t, 0.8, 1}]

Seems to be an issue with manipulate....

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