<< Chapter < Page Chapter >> Page >
Essential skills to use MATLAB effectively.

MATLAB Essentials

Learning a new skill, especially a computer program in this case, can be overwhelming. However, if we build on what we already know, the process can be handled rather effectively. In the preceding chapter we learned about MATLAB Graphical User Interface (GUI) and how to get help. Knowing the GUI, we will use basic math skills in MATLAB to solve linear equations and find roots of polynomials in this chapter.

Basic computation

Mathematical operators

The evaluation of expressions is accomplished with arithmetic operators as we use them in scientific calculators. Note the addtional operators shown in the table below:

Operators
Operator Name Description
+ Plus Addition
- Minus Subtraction
* Asterisk Multiplication
/ Forward Slash Division
\ Back Slash Left Matrix Division
^ Caret Power
.* Dot Asterisk Array multiplication (element-wise)
./ Dot Slash Right array divide (element-wise)
.\ Dot Back Slash Left array divide (element-wise)
.^ Dot Caret Array power (element-wise)
The backslash operator is used to solve linear systems of equations, see [link] .
Matrix is a rectangular array of numbers and formed by rows and columns. For example A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 . In this example A consists of 4 rows and 4 columns and therefore is a 4x4 matrix. (see Wikipedia ).
Row vector is a special matrix that contains only one row. In other words, a row vector is a 1xn matrix where n is the number of elements in the row vector. B 1 2 3 4 5
Column vector is also a special matrix. As the term implies, it contains only one column. A column vector is an nx1 matrix where n is the number of elements in the column vector. C 1 2 3 4 5
Array operations refer to element-wise calculations on the arrays, for example if x is an a by b matrix and y is a c by d matrix then x.*y can be performed only if a=c and b=d. Consider the following example, x consists of 2 rows and 3 columns and therefore it is a 2x3 matrix. Likewise, y has 2 rows and 3 columns and an array operation is possible. x 1 2 3 4 5 6 and y 10 20 30 40 50 60 then x.*y 10 40 90 160 250 360

The following figure illustrates a typical calculation in the Command Window.

Example
Basic arithmetic in the command window.

Operator precedence

MATLAB allows us to build mathematical expressions with any combination of arithmetic operators. The order of operations are set by precedence levels in which MATLAB evaluates an expression from left to right. The precedence rules for MATLAB operators are shown in the list below from the highest precedence level to the lowest.

  1. Parentheses ()
  2. Power (^)
  3. Multiplication (*), right division (/), left division (\)
  4. Addition (+), subtraction (-)

Mathematical functions

MATLAB has all of the usual mathematical functions found on a scientific calculator including square root, logarithm, and sine.

Typing pi returns the number 3.1416. To find the sine of pi, type in sin(pi) and press enter.
The arguments in trigonometric functions are in radians. Multiply degrees by pi/180 to get radians. For example, to calculate sin(90), type in sin(90*pi/180) .
In MATLAB log returns the natural logarithm of the value. To find the ln of 10, type in log(10) and press enter, (ans = 2.3026).

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, A brief introduction to engineering computation with matlab. OpenStax CNX. Nov 17, 2015 Download for free at http://legacy.cnx.org/content/col11371/1.11
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'A brief introduction to engineering computation with matlab' conversation and receive update notifications?

Ask