User Tools

Site Tools


gibson:teaching:fall-2013:math445:lecture1

Matlab diary from lecture 1, Math 445 08/27/2013

format compact
4+2
ans =
     6

4*3 % multiplication is star (asterisk)
ans =
    12
3/4
ans =
    0.7500
4\3
ans =
    0.7500

% precedence
4+3*2
ans =
    10

4+5; % semicolon supresses output


x = 3 % assignment: assign 3 to the variable x
x =
     3

x = 4 + 5
x =
     9

x = x + 1 % Note: as an equation, this is nonsense. But it's an assignment!
x =
    10

x == 10 % This is a boolean expression (Boole) 
ans =
     1
 % 1 means true

x == 11 % this is a boolean expression 
ans =
     0
 % 0 means false

x =
    10


% examples of boolean expressions
x > 7
ans =
     1 % true

x < 14
ans =
     1 % true

x <= 10
ans =
     1 % true

x >= 10
ans =
     1 % true

x >= 17
ans =
     0 % false
pi
ans =
    3.1416


% The Matlab "help" provides help on specific topic and functions, e.g.
help format 

format long
pi
ans =
   3.141592653589793

1/0
ans =
   Inf

acos(2)
ans =
                  0 + 1.316957896924817i

NaN % is Not a Number
ans =
   NaN


% matlab's basic numerical type is a real (complex) number
% plus a couple special numbers: Inf and NaN

% Matlab has different "types" to represetn different type of numbers
% The function "class" rerurns the type of a number

class(pi)
ans =
double
 % "double" means "double precision floating-point number, 16 digits"

pi
ans =
   3.141592653589793

class(1)
ans =
double

int32(1)
ans =
           1

class(int32(1))
ans =
int32

n = int32(1)
n =
           1
class(n)
ans =
int32

% int32 is a 32-bit integer
n = int64(1)
n =
                    1
class(n)
ans =
int64
gibson/teaching/fall-2013/math445/lecture1.txt · Last modified: 2013/08/27 06:44 by gibson