2

デモンストレーション付きのノートブックを作成したいと思います。

SlopeInterceptDemonstration[{mmin_, mmax_}, {bmin_, bmax_}] :=
Module[{xmax, xmin},
xmax = Max[Abs[bmin + mmin], Abs[bmax + mmax]]*1.2;
xmin = - xmax;

Manipulate[
        Plot[m*x + b, {x, xmin, xmax}, AspectRatio -> 1, PlotRange -> {xmin, xmax}],
        {{m, mmin, "m"}, mmin, mmax, 0.1}, {{b, bmin, "b"}, bmin, bmax, 0.1}]
];

単純な呼び出し ( SlopeInterceptDemonstration[{-2, 2}, {-5, 5}] ) を評価してノートブックを保存し、新しいカーネルで再度開いた場合、xmin と xmax がわからないため、デモは表示されません。

Plot 内でこれらの変数の評価を強制する方法はありますか?

4

2 に答える 2

1

のオプションとDynamicModule一緒に使用できます。SaveDefinitionsManipulate

SlopeInterceptDemonstration[{mmin_, mmax_}, {bmin_, bmax_}] := DynamicModule[{xmax, xmin}, 
  xmax = Max[Abs[bmin + mmin], Abs[bmax + mmax]]*1.2;
  xmin = -xmax;
  Manipulate[Plot[m*x + b, {x, xmin, xmax}, AspectRatio -> 1, 
   PlotRange -> {xmin, xmax}], {{m, mmin, "m"}, mmin, mmax, 0.1}, {{b, bmin, "b"}, bmin, bmax, 0.1}, 
   SaveDefinitions -> True]]
于 2012-10-05T10:54:30.700 に答える
0

私はこれがあなたが望むことをすると信じています:

SlopeInterceptDemonstration[{mmin_, mmax_}, {bmin_, bmax_}] :=
 Manipulate[
   Plot[m*x + b, {x, xmin, xmax}, AspectRatio -> 1, PlotRange -> {xmin, xmax}],
   {{m, mmin, "m"}, mmin, mmax, 0.1},
   {{b, bmin, "b"}, bmin, bmax, 0.1},
   {xmax, None},
   {xmin, None},
   Initialization :>
     {xmax = Max[Abs[bmin + mmin], Abs[bmax + mmax]]*1.2, xmin = -xmax}
 ]

{xmax, None}xmaxモジュールでローカライズするために使用されます。DynamicModule他の回答に示されている方法は、標準的でより柔軟です。

于 2012-10-05T12:39:56.973 に答える