MATLAB TUTORIAL for the First Course: Symbolic Math Toolbox

Prof. Vladimir A. Dobrushkin

This tutorial contains many matlab scripts.
You, as the user, are free to use all codes for your needs, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately. Any comments and/or contributions for this tutorial are welcome; you can send your remarks to

Email Vladimir Dobrushkin

Symbolic Math Toolbox

Symbolic Math Toolbox™ provides functions for solving, plotting, and manipulating symbolic math equations. You can create, run, and share symbolic math code using the matlab® Live Editor. Symbolic Math Toolbox lets you analytically perform symbolic calculations, namely, differentiation, integration, simplification, transforms, and equation solving. You can perform dimensional computations and conversions using SI and British unit systems. Your computations can be performed either analytically or using variable-precision arithmetic, with the results displayed in mathematical typeset.

Symbolic Math Toolbox has two important engines: Live Editor and MuPad. With Live Editor, one can interactively explore and rapidly develop mathematical models and algorithms. You can create live scripts, which display symbolic math computations in mathematical typeset alongside matlab code, formatted text, equations, images, and hyperlinks. You can document and share your work as live scripts with other matlab users, or convert them to HTML or PDF for publication. The MuPAD language and symbolic engine can be accessed from the MuPAD Notebook, as well as from the matlab Live Editor and command window. You can convert your MuPAD Notebooks to matlab live scripts.

Here is a short overview of this Toolbox with some simple and useful tools that come with it.

https://math.la.asu.edu/~tracogna/MAT275/MAT275_MATLAB_LABS/MAT275_LAB07.pdf
  • A quick way to make plots: ezplot. Here is the simplest way to make simple plots. The command ezplot sin(t) makes a plot of the sin function on the default interval
  • The command fplot allows one to plot symbolic expressions or functions.
  • A fun tool: funtool. Type funtool and you will be operating plotting calculator that does symbolic calculations. Use this when you need to do some quick checking about a function, its derivative, integral, inverse, etc. The 'help' key explains what the other keys do.
1. A quick way to make plots: ezplot. Here is the simplest way to make simple plots. • The command ezplot sin(t) makes a plot of the sin function on the default interval ( − 2 ; 2  ). More elaborately you can also type ezplot('sin(t)') ; • The command ezplot('t^2/exp(t)',[-1,5]) plots the function t 2 =e t over the interval ( − 1 ; 5).

Lets see some other things the Symbolic Math Toolbox can do, besides mentioned above tools.

syms x a                             % tell matlab that x and a are symbols
f = (x-1)*(x-a)*(x+pi)*(x+2)*(x+3)   % define f
pretty(f)                            % print f in a more readable form
g = expand(f)                        % rewrite f, multiply everything out
h = collect(g)                       % rewrite again by collecting terms
soln = solve(h,x)                    % find all solutions of h = 0
check = subs(f,x,soln(5))            % check, say the fifth solution

matlab has two commands, sym and syms, to declare symbolic variables; of which the latter is simplier (so we mostly will use it). In the above, solve is a powerful command that tries all kinds of things to find a solution. We will discuss other commands in Calculus section.