Main Content

Learn Calculus in the Live Editor

Learn calculus and applied mathematics using the Symbolic Math Toolbox™. The example shows introductory functionsfplotanddiff.

To manipulate a symbolic variable, create an object of typesyms.

symsx

Once a symbolic variable is defined, you can build and visualize functions withfplot.

f(x) = 1/(5+4*cos(x))
f(x) =

1 4 cos ( x ) + 5

fplot(f)

Figure contains an axes object. The axes object contains an object of type functionline.

Evaluate the function at x = π / 2 using math notation.

f(pi/2)
ans =

1 5

Many functions can work with symbolic variables. For example,diffdifferentiates a function.

f1 = diff(f)
f1(x) =

4 sin ( x ) 4 cos ( x ) + 5 2

fplot(f1)

Figure contains an axes object. The axes object contains an object of type functionline.

diffcan also find the N t h 导数。这是二阶导数。

f2 = diff(f,2)
f2(x) =

4 cos ( x ) 4 cos ( x ) + 5 2 + 32 sin ( x ) 2 4 cos ( x ) + 5 3

fplot(f2)

Figure contains an axes object. The axes object contains an object of type functionline.

intintegrates functions of symbolic variables. The following is an attempt to retrieve the original function by integrating the second derivative twice.

g = int(int(f2))
g(x) =

- 8 tan ( x 2 ) 2 + 9

fplot(g)

Figure contains an axes object. The axes object contains an object of type functionline.

At first glance, the plots for f and g look the same. Look carefully, however, at their formulas and their ranges on the y-axis.

subplot(1,2,1) fplot(f) subplot(1,2,2) fplot(g)

Figure contains 2 axes objects. Axes object 1 contains an object of type functionline. Axes object 2 contains an object of type functionline.

e is the difference between f and g . It has a complicated formula, but its graph looks like a constant.

e = f - g
e(x) =

8 tan ( x 2 ) 2 + 9 + 1 4 cos ( x ) + 5

To show that the difference really is a constant, simplify the equation. This confirms that the difference between them really is a constant.

e = simplify(e)
e(x) =
                 
                  
                   
                    1