0% found this document useful (0 votes)
68 views

Example 1: Dean Doneen MATH 2373, Section 011

This MATLAB lab document contains 7 examples demonstrating basic MATLAB operations like arithmetic, variables, commands, and imaginary numbers. Example 1 performs simple integer addition. Example 2 assigns values to variables x and y and adds them. Example 3 divides a variable by an integer. Example 4 performs multiple calculations using variables and commas. Example 5 uses the 'who' command to view defined variables. Example 6 uses pi and adds a comment. Example 7 takes the square root of a negative number, showing MATLAB can handle imaginary results.

Uploaded by

Dean Doneen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Example 1: Dean Doneen MATH 2373, Section 011

This MATLAB lab document contains 7 examples demonstrating basic MATLAB operations like arithmetic, variables, commands, and imaginary numbers. Example 1 performs simple integer addition. Example 2 assigns values to variables x and y and adds them. Example 3 divides a variable by an integer. Example 4 performs multiple calculations using variables and commas. Example 5 uses the 'who' command to view defined variables. Example 6 uses pi and adds a comment. Example 7 takes the square root of a negative number, showing MATLAB can handle imaginary results.

Uploaded by

Dean Doneen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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