# Symbolic Math Toolbox を使用した微積分の学習

Symbolic Math Toolbox™ を使用して微積分と応用数学を学習します。この例では、入門的な関数 `fplot``diff` および `int` について説明します。

```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) ```

```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 ```

```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 ```

```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) ```

```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 ```