第 6 章 函數基本觀念與圖形¶

本章將介紹如何在 wxMaxima 中定義函數、計算函數值、繪製圖形,並探索函數的重要性質,例如定義域、值域、奇偶性與對稱性。本章奠定後續所有函數章節(平移、反函數、複合函數、微分、積分)的基礎。


6.1 在 wxMaxima 中定義函數¶

定義函數的語法為:

f(x) := 表達式;

▶ 範例:定義二次函數¶

In [1]:
f(x) := x^2 - 3*x + 2;
Out[1]:
\[\tag{${\it \%o}_{0}$}f\left(x\right):=x^2-3\,x+2\]

▶ 計算函數值¶

In [2]:
f(1);
f(2.5);
Out[2]:
\[\tag{${\it \%o}_{1}$}0\]
Out[2]:
\[\tag{${\it \%o}_{2}$}0.75\]

6.2 繪製函數圖形:wxplot2d¶

繪圖語法:

plot2d(函數, [x, 最小值, 最大值]);

▶ 範例:繪製二次函數¶

In [22]:
plot2d(x^2 - 3*x + 2, [x, -5, 5])$
No description has been provided for this image

輸出的即是拋物線圖形。


6.3 多函數比較:疊圖¶

可以一次繪製多個函數,來比較圖形。

▶ 範例:一次與二次函數比較¶

In [27]:
f(x) := x^2;
g(x):= x + 1;
Out[27]:
\[\tag{${\it \%o}_{31}$}f\left(x\right):=x^2\]
Out[27]:
\[\tag{${\it \%o}_{32}$}g\left(x\right):=x+1\]
In [29]:
plot2d([f(x), g(x)], [x,-5,5], [y,-2,2])$
plot2d: some values will be clipped.
plot2d: some values will be clipped.
No description has been provided for this image

上面的指令,也可以用視窗選單的 [Plot] -> [Plot 2d] 來做。

若是在選單中的 [Options] 裡 選擇 set size ratio 1; set zeroaxis;,並且把 x, y 的區間設成相同,就可以畫出 x 軸和 y 軸以 1 : 1 顯示的圖形。

In [31]:
plot2d([f(x), g(x)], [x,-5,5], [y,-5,5],
     [gnuplot_postamble, "set size ratio 1; set zeroaxis;"])$
plot2d: some values will be clipped.
plot2d: some values will be clipped.
No description has been provided for this image

6.4 定義域與值域(用圖形理解)¶

wxMaxima 不會自動給出值域,但可透過圖形判讀。

例如:

$$ f(x) = \sqrt{x - 1} $$

▶ 範例:指定繪圖範圍¶

In [33]:
plot2d(sqrt(x - 1), [x, 1, 10])$
No description has been provided for this image

由圖可看出:

  • 定義域:$(1, \infty)$
  • 值域:$(0, \infty)$

6.5 奇函數、偶函數與對稱性¶

奇函數(odd function):

$$ f(-x) = -f(x) $$

偶函數(even function):

$$ f(-x) = f(x) $$

可透過 CAS 做代換檢查:

▶ 檢查奇偶性(自動化)¶

In [9]:
f(x) := x^3 - x;
ratsimp(f(-x) + f(x));   /* 若為 0 → 奇函數 */
ratsimp(f(-x) - f(x));   /* 若為 0 → 偶函數 */
Out[9]:
\[\tag{${\it \%o}_{10}$}f\left(x\right):=x^3-x\]
Out[9]:
\[\tag{${\it \%o}_{11}$}0\]
Out[9]:
\[\tag{${\it \%o}_{12}$}2\,x-2\,x^3\]

由結果可知此函數為奇函數:

▶ 圖形視覺化¶

In [35]:
plot2d(x^3 - x, [x, -3, 3])$
No description has been provided for this image

奇函數會顯示原點對稱。


6.6 分段函數(piecewise function)¶

Maxima 可用 if 定義分段函數。

▶ 範例¶

$$ f(x) = \begin{cases} -x & \text{if } x < 0 \\ x & \text{if } x \geq 0 \end{cases} $$

In [36]:
f(x) := if x < 0 then -x else x;
Out[36]:
\[\tag{${\it \%o}_{41}$}f\left(x\right):=\mathbf{if}\;x<0\;\mathbf{then}\;-x\;\mathbf{else}\;x\]

圖形:

In [38]:
plot2d([f(x)], [x,-5,5])$
No description has been provided for this image

▶ 範例¶

$$ g(x) = \begin{cases} 0 & \text{if } x < 0 \\ x & \text{if } 0 \leq x < 2 \\ 2 & \text{if } x \geq 2 \end{cases} $$

In [39]:
g(x) := if x < 0 then 0
        elseif x < 2 then x
        else 2;
Out[39]:
\[\tag{${\it \%o}_{44}$}g\left(x\right):=\mathbf{if}\;x<0\;\mathbf{then}\;0\;\mathbf{elseif}\;x<2\;\mathbf{then}\;x\;\mathbf{else}\;2\]

圖形:

In [41]:
plot2d([g(x)], [x,-5,5], [y,-3,3])$
No description has been provided for this image

6.7 化簡式子¶

例:判斷函數

$$ f(x) = \frac{x^2 - 4}{x - 2} $$

是否可化成簡單形式。

ratsimp 是常用指令,可將代數式化成「有理式」的最簡形式(rational simplification)。

In [42]:
ratsimp((x^2 - 4)/(x - 2));
Out[42]:
\[\tag{${\it \%o}_{47}$}x+2\]

提醒:原式在 $x = 2$ 不存在。

▶ 三角函數的化簡¶

trigsimp 可以化解三角函數,如:

In [43]:
trigsimp(sin(x)^2 + cos(x)^2);
Out[43]:
\[\tag{${\it \%o}_{48}$}1\]
In [44]:
trigsimp(2*cos(x)^2 + sin(x)^2);
Out[44]:
\[\tag{${\it \%o}_{49}$}\cos ^2x+1\]

▶ 對數的式子整理¶

使用 logcontract 的例子

例:

In [45]:
logcontract(2 *  log(x) + log(y));
Out[45]:
\[\tag{${\it \%o}_{50}$}\log \left(x^2\,y\right)\]

另一例:

In [46]:
logcontract(2 * a * n * log(x));
Out[46]:
\[\tag{${\it \%o}_{51}$}a\,n\,\log x^2\]

用 logexpand 展開式子的例子:

In [47]:
logexpand: all$
log(a * b^2);
Out[47]:
\[\tag{${\it \%o}_{53}$}2\,\log b+\log a\]

6.8 練習題¶

請使用 wxMaxima 完成以下練習:

  1. 定義 $f(x) = x^2 + 2x + 1$,計算:

    • $f(0)$
    • $f(-3)$
  2. 繪製下列函數:

    • $y = x$
    • $y = x^2 - 3x + 2$
    • $y = 2^x$
  3. 判斷下列函數是奇函數、偶函數或皆非:

    • $f(x) = x^3$
    • $g(x) = x^2 - 1$
    • $h(x) = x + 1$
  4. 定義分段函數,並繪圖: $$ f(x) = \begin{cases} x^2, & x \le 0 \\ x, & x > 0 \end{cases} $$

  5. 利用 ratsimp 檢查: $$ \frac{x^3 - x}{x} = x^2 - 1 $$


6.9 本章小結¶

本章你學會:

  • 定義函數並計算函數值

  • 使用 plot2d 或 wxplot2d繪製多種函數圖形

  • 分析函數的定義域、值域與圖形特性

  • 檢查函數的奇偶性

  • 定義並繪製分段函數

  • 使用 CAS 檢查代數化簡是否正確

下一章將介紹函數平移、伸縮、翻轉等變換,幫助學生全面理解函數圖形的變化。