このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
Symbolic Math Toolbox を使用した微積分の学習
Symbolic Math Toolbox™ を使用して微積分と応用数学を学習します。この例では、入門的な関数 fplot
、diff
および int
について説明します。
変数を操作するために、syms
タイプのオブジェクトを作成します。
disp('Create a symbolic variable for x') disp('>> syms x') syms x
Create a symbolic variable for x >> syms x
シンボリック変数を定義したら、関数を作成して fplot
で可視化できます。
disp('Build the function f(x) and plot it') disp('>> f(x) = 1/(5+4*cos(x))') disp('>> fplot(f)') f(x) = 1/(5+4*cos(x)) figure; fplot(f) title('Plot of f(x)')
Build the function f(x) and plot it >> f(x) = 1/(5+4*cos(x)) >> fplot(f) f(x) = 1/(4*cos(x) + 5)
数学的表記を使用して、関数を x = pi/2 で評価します。
disp('Evaluate f(x) at x = pi/2') disp('>> f(pi/2)') f(pi/2)
Evaluate f(x) at x = pi/2 >> f(pi/2) ans = 1/5
シンボリック変数を扱うことができる関数は多数あります。たとえば、関数 diff
は関数を微分します。
disp('Differentiate f(x) and plot the result') disp('>> f1 = diff(f)') disp('>> fplot(f1)') f1 = diff(f) figure; fplot(f1) title("Plot of the derivative of f")
Differentiate f(x) and plot the result >> f1 = diff(f) >> fplot(f1) f1(x) = (4*sin(x))/(4*cos(x) + 5)^2
関数 diff
は N 次導関数も求めることができます。次の例は、2 次導関数を示します。
disp('Compute the second derivative of f(x) and plot it') disp('>> f2 = diff(f,2)') disp('>> fplot(f2)') f2 = diff(f,2) figure; fplot(f2) title("Plot of the 2nd derivative of f(x)")
Compute the second derivative of f(x) and plot it >> f2 = diff(f,2) >> fplot(f2) f2(x) = (4*cos(x))/(4*cos(x) + 5)^2 + (32*sin(x)^2)/(4*cos(x) + 5)^3
関数 int
は、シンボリック変数の関数を積分します。次の例では、2 次導関数を 2 回積分することにより、元の関数を求める試みを示します。
disp('Retrieve the original function by integrating the second derivative twice. Plot the result.') disp('>> g = int(int(f2))') disp('>> fplot(g)') g = int(int(f2)) figure; fplot(g) title("Plot of int(int(f2))")
Retrieve the original function by integrating the second derivative twice. Plot the result. >> g = int(int(f2)) >> fplot(g) g(x) = -8/(tan(x/2)^2 + 9)
一見、f
と g
のプロットは同じに見えます。しかし、式と y 軸の範囲が異なります。
disp('Observe the formulas and ranges on the y-axis when comparing f and g') disp('>> subplot(1,2,1)') disp('>> fplot(f)') disp('>> subplot(1,2,2)') disp('>> fplot(g)') disp(' ') figure; subplot(1,2,1) fplot(f) title("Plot of f") subplot(1,2,2) fplot(g) title("Plot of g")
Observe the formulas and ranges on the y-axis when comparing f and g >> subplot(1,2,1) >> fplot(f) >> subplot(1,2,2) >> fplot(g)
値 e
は、f
と g
の差です。この式は複雑ですが、そのグラフは定数のように見えます。
disp('Compute the difference between f and g') disp('>> e = f - g') e = f - g
Compute the difference between f and g >> e = f - g e(x) = 8/(tan(x/2)^2 + 9) + 1/(4*cos(x) + 5)
差が本当に定数であることを示すために、式を簡略化します。
disp('Simplify the equation to show that the difference between f and g is constant') disp('>> simplify(e)') e = simplify(e)
Simplify the equation to show that the difference between f and g is constant >> simplify(e) e(x) = 1