You are on page 1of 4

Dean Doneen

MATH 2373, Section 011

Lab 01
Example 1

27-48

ans =

-21

Here I used matlab to do simple computation with integers.

Example 2

x=7

x =

y=9

y =

x+y

ans =

16

Here I assigned values to two variables and then added the variables.
Dean Doneen
MATH 2373, Section 011

Example 3

x/7

ans =

Here I used a variable and an integer, the variable is treated as any integer, just being called
upon by a different name (in this case x).

Example 4

x=1, y=3, 3*x+7*y, 9*y, (5*y)/(2*x+y)

x =

y =

ans =

24

ans =

27

ans =

3
Dean Doneen
MATH 2373, Section 011
Here I asked for multiple calculations in one command line, using commas to separate the
different tasks.

Example 5

x =

y =

ans

ans =

who

Your variables are:

ans x y

Here I used the who command to check what my variables were after entering 3 different
variables x, y, and ans.

Example 6

pi % MATLAB uses pi for 3.14159...

ans =

3.1416
Dean Doneen
MATH 2373, Section 011

5+pi

ans =

8.1416

Here I used the % to enter a comment that wasn’t included in the prompt. Pi was displayed as
3.1416, but the comment after the % was ignored.

Example 7

sqrt(-9)

ans =

0.0000 + 3.0000i

Here I took the square root of a negative number, showing that matlab can work with imaginary
numbers.

You might also like