Page 29 - A Guide to MATLAB for Beginners and Experienced Users
P. 29

10        Chapter 2: MATLAB Basics


                       >> v = sin(10)

                       v=
                             -0.5440
                       >> uˆ2 + vˆ2


                       ans =
                             1

                       MATLAB uses double-precision floating point arithmetic, which is accurate
                     to approximately 15 digits; however, MATLAB displays only 5 digits by default.
                     To display more digits, type format long. Then all subsequent numerical
                     output will have 15 digits displayed. Type format short to return to 5-digit
                     display.
                       MATLAB differs from a calculator in that it can do exact arithmetic. For
                     example, it can add the fractions 1/2 and 1/3 symbolically to obtain the correct
                     fraction 5/6. We discuss how to do this in the section Symbolic Expressions,
                     Variable Precision, and Exact Arithmetic on the next page.



           Algebra





                            Using MATLAB’s Symbolic MathToolbox, you can carry out algebraic
                     or symbolic calculations suchas factoring polynomials or solving algebraic
                     equations. Type help symbolic to make sure that the Symbolic Math Tool-
                     box is installed on your system.
                       To perform symbolic computations, you must use syms to declare the vari-
                     ables you plan to use to be symbolic variables. Consider the following series
                     of commands:

                       >> syms x y
                       >> (x - y)*(x - y)ˆ2

                       ans =
                       (x-y)^3
                       >> expand(ans)
   24   25   26   27   28   29   30   31   32   33   34