Lab: Basic MATLAB and Numerical Calculations
Basic Matlab and Numerical calculation
Variables
name = expression;
namemust be meaningful, start with a letter, be unique in the first 31 characters, and are case senstive (use lowercase).- The naming convention is to use lowercase letters
expressioncan be a scalar constant, imaginary and complex number, array expression, another variable, operation, or function- Declare variable type with
typename(value) - Without the
;it will assign AND print it. - If you don't assign a name to the variable, it will default to
ans. - By default, variables in Matlab are always a
double(8 byte decimal number)
Predefined special values should not be used as variables names
Displaying variables
format long|short|rat
Changes the data format value
Mathematical Functions
The difference between rem() and mod():
rem(-7,4) is -3 because it returns X-n.*Y where n=fix(X./Y)
mod(-7,4) is 1 because it returns X-n.*Y where n=floor(X./Y)
Scalar Operations
PEMDAS and from left to right!
Important Commands
clcclears command window- Ctrl+c aborts operation
...continuation%comment
Resources
Linked from Computational Modeling