2012-10-05 3 views
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에서 이러한 변수를 강제 평가할 방법이 있습니까?

답변

1

당신은 ManipulateSaveDefinitions 옵션과 함께 DynamicModule를 사용할 수 있습니다

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]] 
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의 메소드는 표준이며보다 유연합니다.