跳轉到內容

楓葉/圖形函式

來自華夏公益教科書

第 6 章:圖形函式

[編輯 | 編輯原始碼]

簡單繪圖

[編輯 | 編輯原始碼]

要繪製函式,您使用 plot(function) 命令。您需要告訴楓葉它需要針對哪個變數繪製函式值。這是透過 plot(funtion, variable=a..b) 完成的。這將繪製當變數從 a 變化到 b 時函式的值。示例

>plot(x^2, x=0..1);     #Image on the left
>plot(1/3*x^3, x=-1..1);     #Image on the right

您還可以讓楓葉繪製您之前輸入的函式。

>2/3*x^2+x;
>plot(%, x=-2..1);

如果楓葉可以將函式等效於這些極值,它也會接受範圍選項中的變數。如果您正在繪製三角函式,這特別有用,因為您隨後可以使用 π 的倍數。

>plot(cos(x), x=0..2*Pi);     #Image on the left
>a:=Pi:     #Affecting the variable a to equal pi
>plot(sin(x), x=-a..a);     #Image on the right

您可以對繪圖應用許多其他選項。

>plot(x^3+3*x^2+x-1, x=-3..1, colour=blue, style=point, title="This is a title");     #Image on the left
>plot(-x^3-3*x^2-x+1, x=-3..1, colour=green, thickness=2, labels=["X axis label", "Y axis label"], labeldirections=[horizontal, vertical]);     #Image on the right

儲存繪圖

[編輯 | 編輯原始碼]

為了使用(儲存、釋出),圖形應以適當的格式(gif、jpg、pdf、eps)準備並儲存到磁碟。可以使用 plotssetup 命令設定裝置來實現這種轉換。示例

> plotsetup(ps)

此命令指定圖形應以封裝的 Postscript 格式準備。但是,在執行此類命令後,雖然所有其他必要的設定都已良好安排,但 plot 命令可能會導致錯誤。因此,在執行此類命令後,命令

> plotsetup(default)

可能非常有用;尤其是在使用者嘗試逐個嘗試所有選項以找出將圖片寫入檔案的命令組合時。

但是,還存在一種透過使用選單儲存圖片的方法。使用者應單擊圖形(“標記它”),然後在頂部選單欄中找到選項 **繪圖** 並開啟其底部的二級選單“匯出”,使用者必須在其中選擇要匯出的檔案格式。對於儲存或更新的每張圖片,都應重複此操作。

在單一繪圖中顯示多個圖形

[編輯 | 編輯原始碼]

t2 := plot(g2(y), y = 1 .. 10, color = red): t4 := plot(g4(y), y = 1 .. 8, color = blue): t6 := plot(g6(y), y = 1 .. 8): display({t2, t4, t6});

楓葉顯示三條曲線

繪圖的旋轉和反射

[編輯 | 編輯原始碼]
楓葉繪圖旋轉

>K2 := plot(g2, y = 0 .. 10,color=red): plottools:-reflect(plottools:-rotate(K2, (1/2)*Pi), [[0, 0], [0, 1;

K4:= plot(g4, y = 0 .. 10,color=blue): plottools:-reflect(plottools:-rotate(K4, (1/2)*Pi), [[0, 0], [0, 1]]);

>K6 := plot(g6, y = 0 .. 10, color = black); plottools:-reflect(plottools:-rotate(K6, (1/2)*Pi), [[0, 0], [0, 1]]);

楓葉顯示兩條曲線旋轉和反射
楓葉顯示三條曲線旋轉和反射


with(plots); animate(subs(k = .5, f), x = -30 .. 30, t = -10 .. 10, numpoints = 200, frames = 50, color = red, thickness = 3);

|

鐘形孤子



animate3d(cos(t*x)*sin(3*t*y), x = -Pi .. Pi, y = -Pi .. Pi, t = 1 .. 2)

3D 動畫
華夏公益教科書