An Overview of Matlab: Computational Techniques
An Overview of Matlab: Computational Techniques
An Overview of Matlab: Computational Techniques
An Overview of
MATLAB®
Order of precedence
An Example Session,
>> 8/10
ans =
0.8000
>> 5*ans
ans =
4
>> r=8/10
r=
0.8000
>> r
r=
0.8000
>> s=20*r
s=
16 Dr S Z Sayed Hassen Dr S Z Sayed Hassen
1-4 1-5
Dr S Z Sayed Hassen 1
Computational Techniques
Examples of Precedence,
Examples of Precedence,
>> 8 + 3*5
>> 3*4^2 + 5
ans =
ans =
23
53
>> 8 + (3*5)
>>(3*4)^2 + 5
ans =
ans =
23
149
>>(8 + 3)*5
>>27^(1/3) + 32^(0.2)
ans =
ans =
55
5
>>4^2128/4*2
>>27^(1/3) + 32^0.2
ans =
ans =
0
5
>>4^212 8/(4*2)
>>27^1/3 + 32^0.2
ans =
ans =
3
11
Commands for managing the work session Special variables and constants
Dr S Z Sayed Hassen 2
Computational Techniques
>>a = [1,-7,40,-34];
>>roots(a)
ans =
3.0000 + 5.000i
3.0000 - 5.000i
1.0000
Dr S Z Sayed Hassen 3
Computational Techniques
Dr S Z Sayed Hassen 4
Computational Techniques
1. The name of a script file must begin with Program errors usually fall into one of the
a letter, and may include digits and the following categories.
underscore character, up to 63 1. Syntax errors such as omitting a parenthesis
characters. or comma, or spelling a command name
2. Do not give a script file the same name incorrectly. MATLAB usually detects the
as a variable. more obvious errors and displays a message
3. Do not give a script file the same name describing the error and its location.
as a MATLAB command or function. You 2. Errors due to an incorrect mathematical
can check to see if a command, function procedure, called runtime errors. Their
or file name already exists by using the occurrence often depends on the particular
exist command. input data. A common example is division by
Dr S Z Sayed Hassen
zero. Dr S Z Sayed Hassen
1-24 1-25
3. Calculation section
1-28
Dr S Z Sayed Hassen Dr S Z Sayed Hassen
1-29
Dr S Z Sayed Hassen 5
Computational Techniques
Dr S Z Sayed Hassen 6
Computational Techniques
1-36 1-37
Dr S Z Sayed Hassen Dr S Z Sayed Hassen
Dr S Z Sayed Hassen 7