2012-01-09 46 views
3

說,同時改變ab數學操縱劇情:縮放軸

f[a_,b_,c_]:=a b c Exp[a b] 

Manipulate[ 
Plot 
[ 
f[a,b,c], 
{c,0,1}, 
PlotRange->{{0,0.05},Automatic} 
], 
{a,0,1}, 
{b,0,1} 
] 

我已經設置了以下功能f[a,b,c]我想情節是有可能有,當我修復橫座標觀看縱座標自動縮放範圍?你會注意到上面的代碼,當變化ab縱座標確實自動縮放,如果我正在查看整個範圍{c,0,1}。我希望它仍然能夠從0到1處理c,但是如果我想查看此圖的較小部分,比如說從0到0.05的c,仍然可以正確縮放垂直軸。感謝大家的幫助。

+0

如果有方法將PlotRange添加到Manipulate中,我會非常棒,但到目前爲止我還沒有發現任何說這是可能的... – CaptanFunkyFresh 2012-01-09 22:51:33

回答

8

上阿特斯Docendo的建議的變體:

Manipulate[ 
Plot[f[a, b, c], {c, 0, [email protected]}, 
    PlotRange -> {{0, [email protected]}, Full}], {a, 0., 1.}, {b, 0., 1.}, {d, 
    0.05, 1.}] 

通知的Evaluate迫使機器精度值實際送入Plot功能之前,試圖畫出一些東西。

在這種情況下,我更喜歡Full而不是Automatic,因爲那樣你就知道它永遠不會以隱藏曲線部分的方式裁剪圖。

4

這裏是許多可能的解決方案之一:

f[a_, b_, c_] := a b c Exp[a b] 
Manipulate[ Plot[f[a, b, c], {c, 0, d}, PlotRange -> Automatic], 
      {a, 0, 1}, {b, 0, 1}, {d, 0.1, 1}, Initialization :> (d := 0.1)] 

但是你的例子也不是很有益的,看看它是如何工作的最好嘗試像 一些這樣的:

g[a_, b_, c_] := 3 (a - 0.5) Cos[4 Pi (a - c)] Sin[8 Pi (c - 0.5)] Cos[6 Pi (b - c)] 

Manipulate[ 
      Plot[g[a, b, c], {c, 0, d}, PlotRange -> Automatic], 
      {a, 0, 1}, {b, 0, 1}, {d, 0.1, 1}, 
      Initialization :> (a := 0.4; b := 0.4; d := 0.5)] 
3

看看這樣做你想要什麼。我只是使用ListPlot而不是plot。

但我不確定你在做什麼,因爲你正在繪製f c從0到1,但是然後將x範圍設置爲0到0.05?那麼爲什麼不使用{c,0,0.05}來繪製f呢?可能是我錯過了一些東西。

無論如何,這裏是我

Manipulate[ 

xmax = 0.05; 
y = Table[f[a, b, c], {c, 0, xmax, 0.01}]; 
max = Max[y]; 
min = Min[y]; 

Plot[f[a, b, c], {c, 0, 1}, 
    PlotRange -> {{0, xmax}, {min, max}}, ImagePadding -> 30], 

{a, 0, 1}, 
{b, 0, 1}, 
Initialization :> 
    (
    f[a_, b_, c_] := a b c Exp[a b] 
    ) 

] 

編輯(1)

它只是發生在我身上,使上面的更高效,是使用第一個表的命令,以生成數據本身,而不僅僅是查找繪圖範圍的最大/最小值。然後用ListPlot代替Plot。這應該更快,所以功能f的採樣只發生一次而不是2次?

因此,這裏是第二個版本

Manipulate[xmax = 0.05; 

data = Table[{c, f[a, b, c]}, {c, 0, xmax, 0.01}]; 
max = Max[data[[All, 2]]]; 
min = Min[data[[All, 2]]]; 

ListPlot[ 
    data, 
    PlotRange -> {Automatic, {min, max}}, 
    Joined -> True, 
    ImagePadding -> 30 
    ], 

{a, 0, 1}, 
{b, 0, 1}, 
Initialization :> 
    (
    f[a_, b_, c_] := a b c Exp[a b] 
    ) 
]