Professional Documents
Culture Documents
CS701 2015lecture02
CS701 2015lecture02
CS701, 02
(ScD), .
S.CS701, 02
, ,
:
,
o
o
M
, , , , .
Matlab
.
.
.
, .
1.
.
2-1: . :
5+5
3^2
sin(pi/2)
. .2-1- .
(ScD), .
S.CS701, 02
2-1. 2-1-
.
2-2: . :
9/0
. .2-2- .
2-2. 2-2-
Matlab .
2-3: . :
732*20.3
. .2-3- .
(ScD), .
S.CS701, 02
2-3. 2-3-
Matlab
.
2-4: . :
x=3;
y=x+5
. .2-4- .
2-4. 2-4-
2. ,
.
.
.
= .
.
2-5: x 3 . :
x=3
% 3
. .2-5- .
(ScD), .
S.CS701, 02
2-5. 2-5-
1 .
. :
.
.
ans .
2-6: .
:
x=sqrt(16)
sqrt(78)
. .2-6- .
2-6. 2-6-
ans .
ans
.
2-7: ans . :
(ScD), .
S.CS701, 02
9876/ans
. .2-7- .
2-7. 2-7-
.
2-8: ans . :
a = 2; b = 7; c = a * b
. .2-8- .
2-8. 2-8-
.
.
2-9: ans . :
initial_velocity = 0;
acceleration = 9.8;
time = 20;
final_velocity = initial_velocity ...
+ acceleration * time
. .2-9- .
(ScD), .
S.CS701, 02
2-9. 2-9-
(short format)
4- .
(format long) 16- .
2-10: . :
format long
x = 7 + 10/3 + 5 ^ 1.2
format short
x = 7 + 10/3 + 5 ^ 1.2
. .2-10-
.
2-10. 2-10-
.
format bank format short e, format long e .
(ScD), .
S.CS701, 02
2-11: format bank . :
format bank
daily_wage = 177.45;
weekly_wage = daily_wage * 6
. .2-11-
.
2-11. 2-11-
2 .
2-12: format short e . :
format short e
4.678 * 4.9
. .2-12-
.
2-12. 2-12-
4 .
2-13: format long e . :
format long e
x = pi
(ScD), .
S.CS701, 02
. .2-13-
.
2-13. 2-13-
16 .
3.
Matlab
. .
3.1.
.
clc
clear
exist
global
help
lookfor
quit
who
whos
MATLAB
who
. 1- .
.
2-1: .
3.2.
.
cd
date
delete
(ScD), .
S.CS701, 02
dir
load
path
pwd
save
type
what
wklread
MATLAB
.wk1 .
2-14. pwd
.2-14- pwd .
.
. , C Users
Uranchimeg Documents
MATLAB ( 2-15).
.
.
,
. ,
(yahoo, skype ..), (mozilla, thunderbird, gmail,
yahoo, hotmail ..), (paint, photoshop, picasa .)
(word, excel, latex ..) .
.
. pwd
. .
.
. . 2-15
(ScD), .
10
S.CS701, 02
,
.
2-15. pwd
2-2: .
4. M
. <<
.
.
(ScD), .
11
S.CS701, 02
.
.
m . .m
. Word
.doc .
.m 2 . :
Scripts files .
.
. .
.
Functions .
.
.
.
.
2-14: m . :
mkdir progs
chdir progs
edit CS701_Practice1.m
. .2-16-
.
. 2-16-
.
.
.
NoOfStudents = 6000;
TeachingStaff = 150;
NonTeachingStaff = 20;
Total = NoOfStudents + TeachingStaff ...
+ NonTeachingStaff;
disp(Total);
.
(ScD), .
12
S.CS701, 02
2-16. 2-14-
2-17.
(ScD), .
13
S.CS701, 02
2-18.
. File/Save File/Save as
Ctrl+S . ( Save
.)
.
dir .
( 2-18).
.
type ( 2-19).
2-19. type
run .
( 2-20).
2-20.run
2-3: .
a = 5; b = 7;
c=a+b
d = c + sin(b)
(ScD), .
14
S.CS701, 02
e=5*d
f = exp(-d)
5.
.
. 99
1--1 .
int8
uint8
int16
uint16
int32
uint32
int64
uint64
single
double
logical
char
8-
8-
16-
16-
32-
32-
64-
64-
1 0 , true false
o
(
o )
2-15: . :
str = 'We are learning Matlab'
n = 2345
d = double(n)
un = uint32(789.50)
c = int32(rn)
. .2-21-
.
. [7] .
(ScD), .
15
S.CS701, 02
2-21. 2-15-
2-4: .
x=3
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)
isnumeric(x)
x = 23.54
isinteger(x)
(ScD), .
16
S.CS701, 02
isfloat(x)
isvector(x)
isscalar(x)
isnumeric(x)
x = [1 2 3]
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)
x = 'I am student'
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)
isnumeric(x)
6.
:
.
. , , ,
.
2 .
. .
. 2-
. (i,j)- i-
(ScD), .
17
S.CS701, 02
2- j-
.
2-16: . :
a = [ 1 2 3; 2 3 4; 1 2 5]
b = [ 2 1 3 ; 5 0 -2; 2 3 -1]
prod = a * b
. .2-22-
.
2-16. 2-22-
:
18 . ?
prod(1,1)=a(1,1)*b(1,1)+ a(1,2)*b(2,1)+ a(1,3)*b(3,1)=1*2+2*5+3*2=18
.
2-5: 2-16
.
(ScD), .
18
S.CS701, 02
[8] .
2-
,
. .
.
,
.
(ScD), .
19
S.CS701, 02
[1] Matlab Guide 2nd ed. D.J. Higham & N.J. Higham SIAM Philadelphia, 2005, ISBN: 089871-578-4.
[2] http://www.mathworks.com/academia/students.html?s_tid=gn_ac_sh Matlab
[3] http://www.tutorialspoint.com/matlab/matlab_quick_guide.htm -
[4] Matlab a Practical Introduction to Programming and Problem Solving 3th ed. Stormy
Attaway, Walthham, MA 02451, USA, 2013, ISBN: 978-0-12-405876-7.
[5] Essential Matlab 5th ed. Brain H.Hahn and Daniel T. Valentine, Walthham, MA 02451,
USA, 2013, ISBN: 978-0-12-394398-9.
[6] http://www.mathworks.com/products/matlab/ - Matlab
[7] http://www.tutorialspoint.com/matlab/matlab_data_types.htm -
[8] http://www.tutorialspoint.com/matlab/matlab_operators.htm -
(ScD), .
20