Historically, memory was scarce so engineers chose 32 bits for
a real number, calling it the “single-precision”
format and dividing the bits between fraction and exponent to
provide about 7 decimal digits, range about ±1037
But sometimes more range or precision was needed, so engineers
also provided a “double-precision” format with about
15 digits, range about ±10300
Nowadays, double precision is the norm for real numbers, including
in Matlab
Integer types
Unsigned vs signed
Different numbers of bits
Types can also imply different behavior, e.g., division
>> realmax
ans =
1.7977e+308
>> realmin
ans =
2.2251e-308
>> 1/2
ans =
0.5000
>> uint8(1) / uint8(2)
ans =
1
Variable names are case-sensitive
Differently-spelled names can mean different things
Camel case typographical convention
Keywords are predefined words that can’t be names
(e.g., if, for, switch, … )
But many important built-in names can be over-written by your own values
Complex values can use i or j
Programming variables vs math variables
Math: variables are abstraction of values
So use variables to emphasize a relationship or when uncertain
as to value, eg., cos x = x
Or when you want to talk about a large number of values, e.g.,
for all numbers x and y, x + y = y + x
Programming: variables are abstractions of memory storage
x = cos x means something very different when talking
about depositing a new value in memory “x” than
it does when talking about a mathematical relationship
Programming variables have to have definite value
Abstraction: focusing as some aspects of something while supressing
other details
Arithmetic Lab
Think about part 2, watch videos, be ready to ask questions if
you have them Wednesday
Next
Algorithms
Watch “What
Is An ‘Algorithm’?” video at
https://cloud.ensemblevideo.com/app/sites/index.aspx?destinationID=IlO-D-b-vUWVkAsj2Is5Zg