Sei sulla pagina 1di 11

About you

Talk to one other person, find out


Their name
Where they are from
Their two favorite hobbies
Their major or intended major
Introduce them to 4 other people

Engineering
Education
1s
A bit is the most basic unit of computing and
0s
Has a value of 0 (false) or 1 (true)
Collections of bits called a word (e.g. 011 or 11010101)
Multiple bits can be strung together to form bigger units
Bytes (8 bits)
Kilobytes (1000 bytes)
Megabytes (1000 kilobytes)... etc

Engineering
Education
ABCs
Some Basic Data Types and
123s
Boolean
Single bit, 1 = true, 0 = false
Integer
Whole numbers
Signed (can be negative) or Unsigned (cant be negative)
Decimal
Real numbers
Characters
Letters (A B C x y z) and symbols (, . / ! ?)

Engineering
Education
ABCs
Data Types - Example and
123s
10010011
Unsigned integer 147
Signed integer -109
ASCII extended character
The point
We need to know what the 1s and 0s represent to make sense of them, use
computers for anything besides binary operations

Engineering
Education
Problems 1 and 2

Engineering
Education
Programming
MATLAB Syntax - Variables

Variables are abstract representations of information


Variables will have a data type
Assigning values to variables in MATLAB
Use the symbol =
Put variable name to the left
Put value to the right
X = 2.8;
Y = 5000;
myLastInitial = B;
You can assign variables the values of other variables:
X = Y;
Engineering
Education
Programming
MATLAB Syntax and Style
Naming Variables
Rules:
No spaces my variable = 10;
No special characters #$*!@ = A;
Underscores OK
Cant start with numbers 1coolVariable = 42;
It can only help you to use descriptive variable names
Good:
itemWeight = 25;
lowest_common_denominator = 3;
Bad:
thingy = 1;
aaa = 111*thingy;

Engineering
Education
Programming
MATLAB Syntax - Semicolons

In general, you will want to put a semicolon (;) at the end of every line
of code that assigns a value to a variable
Suppresses output
Forgetting this
Wont stop your program from running
Will give you a headache

Engineering
Education
Programming
MATLAB Syntax Operators
Basic arithmetic
Addition (+): x = 1+1;
Subtraction (-): x = 2-6;
Multiplication (*): z = 400*10;
Division (/): oneThird = x/3;
Exponents
Use the carrot (^): twoSquared = 2^2;

Engineering
Education
Programming
MATLAB Style - Comments

Comments are an important component of good style, no matter the


programming language
Comments Text in a program that is ignored by the computer when
running
Denoted by %
Example:
%This is a comment. It helps everybody understand my program.

Engineering
Education
Programming
MATLAB Style Why?
%This simple script x = 20;
calculates the distance a y = 45;
vehicle can travel.
z = x * y;
gasTankSize = 20; %Gas tank
volume in gallons
fuelEfficiency = 45;
%Engine efficiency in miles
per gallon
distance = gasTankSize *
fuelEfficiency; %The range
of the vehicle
Engineering
Education

Potrebbero piacerti anche