MATLAB Technical: Computing Environment
MATLAB Technical: Computing Environment
Computing
Environment
Display Windows
Command window Enter commands and
data, display results Prompt >> or EDU>>
Getting Help
Interrupting and
Terminating MATLAB
Numbers 2.2.1
MATLAB represents numbers in two forms:
1.
Fixed point: Decimal form, with an optional
decimal point. For example: 2.6349 , -381
, 0.00023
2.
Floating point: Scientific notation, used
when numbers are very large or very small.
Representing m 10e For example: 2.6349
105 is represented as 2.6349e5, the
number has two parts:
Operators 2.2.2
Operation
Algebraic form
MATLAB
Addition
a+b
a+b
Subtraction
a-b
a-b
Multiplication
ab
a*b
Right division a b
a/b
Left division
ba
a\b
Exponentiation
ab
a^b
Execute the commands in pages16, 17
Syntax
commands must be written using the correct
syntax (rules for forming commands).
When a syntax error is made the command
will not be executed and an error message
appears on the command line telling us what
the error is.
Examples of these messages( missing
operator, undefined variable)
Assignment statement
When a command of the form:
variable = number
variable = expression
Is executed the expression is evaluated,
producing a number that is assigned to the
variable. The variable name and its value are
displayed.
If a variable name is not specified, MATLAB
will assign the result to the default variable
(ans)
Special variables:
Do example 2.2
Redefining variables
A variable may be redefined simply by
executing a new assignment statement
involving the variable.
previously issued commands involving the
redefined variable wont be automatically
reevaluated.
Do example 2.3
abs(x)
Absolute value |x|
sign(x)
Sign, returns -1 if x < 0, 0 if x = 0, 1 if x> 0
exp(x)
Exponential ex
log(x)
Natural logarithm ln x
log10(x) Common (base 10) logarithm log10 x
sqrt(x) Square rootx
rem(x,y) Remainder of x/y. For example, rem(100,21) is 16. Also
called the modulus function.
For a complete list print: help elfun
Do examples 2.5, 2.6
Computational 2.4
Limitations
MATLAB Command
ratio
Comments
format short
50.8333
4 decimal digits
format long 50.83333333333334
14 decimal digits
format short e
5.0833e+001
4 decimal digits plus exponent
format long e
5.083333333333334e+001 14 decimal digits plus
exponent
format short g
50.8333
better of format short or format
short e (default), switching for ans > 1000
format long g
5.083333333333334e+001 better of format long or
format long e
format bank 50.83 2
decimal digits
format +
+
positive, negative, or zero
2. disp:
There are two general forms of the command disp that
are useful in displaying results and annotating
:them with units or other information
3.fprintf: