Professional Documents
Culture Documents
Review of Lecture 2
Matrix
=> X=A/B=AB-1
AX=B => X=A\B=A-1B
Example
Suppose we have invested some money
Outline
Looping and branching statements
if
select/case
for
while
break
Continue
return
Function
User-defined functions
User-defined library
Debugging: pause, abort, resume
4
Order of commands
Sequence: one by one consecutively
Command 1
Command 2
Command 3
5
Branching: if
Selection/Decision Among Multiple Cases
Commands
Conditi
on?
True
True Block
Commands
6
Branching: if
Selection/Decision Among Multiple Cases
Commands
False
False Block
Commands
Conditi
on?
True
True Block
Branching: select/case
Multiple
possibilitie
s
Test
expression
Case 1
Case 2
Case 3
Command
Case 4
10
Flowchart
Command 1
Command 2
Command 3
11
if
False
Conditi
on?
False Block
select
case
Case 1
True
True Block
Test
expression
Case 2
Case 3
Command
Case 4
12
13
Alternativ
ely
14
for
while
Given a number
of repetitions
Condition is True
Block 1
Block 1
Conditi
on?
False
Block 2
15
Block 2
loop
16
17
Example
Suppose we have invested some money
18
Example
19
Functions
y=f(x);
internal function y=sin(x)
20
Functions (2)
21
Functions (3)
>>z=myfunction(9)
22
Functions(4)
Multiple output arguments
23
Scilab/MATLAB:
function
f=simplef(x1,x2)
f(1)=2*x1;
f(2)=3*x2;
endfunctioin/end
>simplef(1,2)
>ans= 2 6
Functions(5)
A function
can call
another
function
24
Functions(6)return
statement
return statement allow to immediately
25
Function Libraries
A function library is a collection of functions
26
Example-genlib
Library
name
27
Directory containing
*.sci files
Exampleload library
Location: Operation System
dependent
28
Home Work-3
Due: 9am, Sep 21, 2015
Late policy: 10% off per day
To be submitted online to Canvas.
Both answers and your codes (*.sec files)
are required to submit; Do use // to add
comments clearly which question you are
referring to. when we execute your codes,
answers shall be shown on the screen.
following?
30
following?
31
following?
32
HW3 - Exercise(4)
What will you get by executing the
following?
33
HW3 - Exercise(5)
What will you get by executing the
following?
34
HW3 - Exercise(6)
What will you get by executing the
following?
35
HW3 - Exercise(7)
What will you get by executing the
following?
36
Use whileend
37
HW3 - Exercise(9)
Write some Scilab statement on the
38
HW3 - Exercise(10)
The Internal Revenue Service (US) decides
39
HW3 - Exercise(11)
The electricity accounts of residents in a very small rural
the cost is $10 for the first 500 units and 5 cents for every
units in excess of 500
If more than 1000 units are used, the cost is $35 for the first
1000 units plus 10 cents for every units in excess of 1000
A basic service fee of $5 is charged no matter how much
electricity is used.
Five resides use the following units of electricity in a
HW3 - Exercise(12)
(help
grand)
41