Anda di halaman 1dari 4

Basic Calculations and Graphing In MATLAB

Written by Aaron Oleson

Introduction to matlab
MATLAB is a multifunctional computer program that allows its users to calculate a variety of different math equations,
compute algorithms, and graph/ plot functions and various sets of data. This program is extremely useful in many
professional fields as well as for students in majors including engineering and economics. One of its most important
functions is its ability to help its users produce graphs of complex functions. In this set of instructions you will learn the
basics of calculating on MATLAB and how to graph/ plot on the MATLAB program. After reading these instructions you
will be able to compute basic calculations and create graphs of data or functions that can be used for anything from
analyzing data in engineering to studying supply and demand curves in economics. These instructions are geared to give a
user new to MATLAB skills that can be used throughout their college courses and professional careers.

Important Preliminary Knowledge


Downloading Software: MATLAB can be use on both Windows computers and Macs. If you do not currently have the
program, you can download it from the Mathworks website at http://www.mathworks.com/products/matlab/.
The Main Screen
Once MATLAB is downloaded onto your computer open the program. Once open you will be viewing the MATLAB
main screen (Figure 1)
Figure 1:

Workspace

Command
Window
Command
History

There are three main features to the main screen as shown in figure 1.
Command Window: Where the user enters the operation commands and data for graphing/ plotting.
All operation commands are typed in next to the double right arrows (>>) and are completed upon
hitting the enter/ return key.
Command History: A list of previously entered commands.
Workspace: In the workspace the data sets will be listed.
Throughout this set of instructions the most important window will be the command window as it will be where
you are entering the calculation and graphing operation commands.

Basic Calculating Instructions


Written Instructions:

Visual Instructions:

1. Open MATLAB so you are


looking at the main screen.
(Figure 2)

Figure 2:

In this part of the instructions


we will be examining some
basic calculations that can be
preformed on MATLAB.
To start enter a=3 into the
command window. This is
called a scalar. (Figure 2)
In the next steps we will try
commands for calculating with
scalars.
2. To add to or subtract from
another number enter the
addition or subtraction
command. (Figure 3)

Figure 3:

Input: a+1
Input: 5-a
3. Now try multiplication and
division with there relative
commands. (Figure 3)
Input: a*5
Input: a/4
4. Exponents can also be used in
MATLAB using exponential
commands. (Figure 4)
Input: a.^2
Note: A period must be entered
before the carrot symbol when
entering an exponent.
5. Try creating a polynomial
with various scalar commands.
(Figure 4)
Input: a.^2+2*a+5

Figure 4:

MATLAB can also be used for


calculations of vector quantities.

Figure 5:

6. First enter a simple vector with


i, j, and k (x, y, and z)
components. Make sure to leave
spaces between the numbers.
(Figure 5)
Input: b= [2 4 6]
With this we can do vector-scalar
calculations.
7. To add or subtract a vector to a
scalar use the regular addition/
subtraction commands as you did
with the scalars. (Figure 5)
Input: b+1
Input: b-1
8. The commands are also the
same for multiplication or
division of a vector and a scalar.
(Figure 5)
Input: b*2
Input: b/2
Now we are going to try vectorvector calculations.
9. To do this we will start by
creating another vector.
Input: c=[3 6 9] , This will work
for addition/ subtraction but we
need a column vector for
multiplication/ division.
Input: d=[3 6 9] , To make a
column vector add an apostrophe
to the regular vector command.
(Figure 6)
10. To add or subtract the two
vectors we simply use the
addition and subtraction
commands. (Figure 6)
Input: b+c
11. For multiplication and
division we also use the regular
multiplication and division
commands. (Figure 6)

Input: b*d

Figure 6:

The last of the basic commands


I will go over are for matrices.

Figure 7:

12. To create a matrix enter the


values as the matrix should
appear. Make sure to leave
spaces in between separate
numbers. The command will not
enter until you type the closing
bracket. (Figure 7)
Input: e=[1 2 3
456
7 8 9]
13. To find the value of a
number in the matrix type in its
row than column. (Figure 7)

Figure 8:

Ex: If you enter e (2, 3) you are


returned the value 6.
Try this input, e (2, 3).
14. To add or subtract the
matrix to a scalar we simply use
the regular addition and
subtraction commands.
(Figure 8)
Input: e+2
15. For multiplication and
division we also use the regular
multiplication and division
commands.
(Figure 8)

Figure 9:

Input: e*3
16. In order to do calculations
with two matrices we first have
to create another. (Figure 9)
Input: f=[2 4 6
8 10 12
14 16 18]
17. To add or subtract these
matrices simply input f+e or f-e.
(Figure 9)
18. To multiply or divide these
matrices simply input f*e or f/e.
(Figure 9)

These are the basic calculations that can be preformed on MATLAB. The next
part of the instructions will teach you how to graph/ plot on MATLAB.

Anda mungkin juga menyukai