If you look carefully, you'll see that MATLAB indents its answer when the answer is numerical (double-precision) and prints it flush with the left margin when the answer is symbolic. So now when we take the sine, we get the exact answer 0. (which MATLAB denotes simply by pi) but to the exact number. So sym('pi') refers not to the approximate number 3.14159265. The command sym takes a string as an argument and tells MATLAB to interpret this string as a symbolic expression. Matlab responds withĪ string of characters, enclosed in single quotes, is what MATLAB calls a string. For example, notice what happens if you type sin(sym('pi')) and hit Enter. It can also do exact, i.e., symbolic, calculations and algebra, using an accessory called the Symbolic Toolbox, but only if you tell it to. It is important to remember that MATLAB, by default, does numerical calculations with double-precision numbers. The basic operations and functions are represented by * for "times", / for "divided by", ^ for powers (e.g., 3^3 means "3 cubed"), abs for absolute value, sqrt for square root, exp for the exponential function to the base e, so exp(1)=2.718281828., log for the logarithm function to the base e (often denoted ln), sin, cos, and tan for the basic trig functions, cosh, sinh, tanh for the basic hyperbolic functions, and asin, acos, atan for the inverse trig functions. ExerciseĮxperiment with using the MATLAB Command Window as a calculator. Thereafter, MATLAB will print out 15 significant digits (unless you go back to the default by typing format short). The MATLAB default is to print five digits, but you can change this by typing format long and hitting Enter. This is because MATLAB does arithmetic with double-precision numbers, which are only accurate to 15 places. Of course, but MATLAB gave the numerical answer (in scientific notation). MATLAB recognizes sin as the sine function and pi as the number. MATLAB should type in response something like: ans = 1.2246e-016 In this way you can use MATLAB as a calculator. Position your mouse there and typeĪnd hit Enter. In the command window you should see a prompt that looks like >. In the toolbar, change the Current Directory to the directory or folder where you want to save your work.
#Matlab symbolic toolbox plot windows
(The function of the other windows is explained in Chapter 3 of A Guide to MATLAB® for Beginners and Experienced Users, second edition, by Hunt, Lipsman and Rosenberg.) You should see the MATLAB Desktop which includes several windows, the most important of which is the MATLAB Command Window.