You are on page 1of 14

http://chunguv.blogspot.

com

Bi Tp Thc Hnh Tin Hc Chuyn Ngnh.


Bi Tp Thc Hnh S 1 :( Thc hnh lnh, kiu d liu, ton t, truy cp,
mng, hm trn ca s lnh).
1) Lm quen vi mi trng ca s lm vic Matlab.

+ Command Window (Ca s lnh ).


+ Current Directory ( Ca s th mc hin hnh ).
+ Command History (Ca s lch s ).
+ Work Space ( Khng gian lm vic )
2) Thc hin cc lnh chc nng trn ca s lnh.
clc, clear, home, help, edit, type, , , , , end, esc delete, backspace, Ctrl+k, shift
+ home, shift + end.
3) Gn cc kiu d liu cho bin .
D liu s nguyn, d liu s thc, d liu s phc, pi, eps, realmin, realmax, inf,
Nan.
4) nh dng cc kiu d liu s vi lnh format : long, long e, short, short e, trong
e l c s 10

http://chunguv.blogspot.com
5) Qui c bin v thc hin cc php ton trn ca s lnh.
Cng +, tr -, nhn *, chia phi /, chia tri \, ly tha ^
6) Lm vic vi mng trn ca s lnh.
+ Gn d liu nguyn, thc, phc cho mng mt chiu, hai chiu, ba chiu bng ch
s, bng ni dung.
+ Truy cp mng mt chiu, hai chiu bng ni dung v ch s.
Vi ch s, A(i,j) truy cp phn t c ch s i,j, A(1:,k,j) truy cp t phn t th nht
n phn t th k ca ct j, A(i,1:k) truy cp t th 1 n phn t th k ca hng i,
A(:,j) truy cp tt c cc phn t ca ct j, A(i,:) truy cp tt c cc phn t ca hng i.
7) Thc hnh mt s hm vi mng trn ca s lnh.
Sum, prod, diff, trace, diag, eye, ones, zeros, magic, randn, inv, eig . . .
8) Thc hnh cc php ton mng trn ca s lnh.
Cng +, tr -, nhn *, chia phi /, chia tri \, ly tha ^, ton t chuyn v , ton t
nhn hai phn t tng ng .*, ton t chia phi hai phn t tng ng ./, ton t chia
tri hai phn t tng ng .\, ton t ly tha tng mi phn t .^.
9) Thc hnh cc ton t logic vi mng trn ca s lnh.
Ton t logic and &, ton t logic or |, ton t logic not ~.
10) Thc hnh cc php ton so snh vi mng trn ca s lnh.
Ton t nh hn <, ton t ln >, ton t nh hn hoc bng <=, ton t ln hn hoc
bng >=, ton t ==, ton t khng bng ~=.
=================Ht Bi Tp Thc Hnh s 1 ====================

http://chunguv.blogspot.com

Bi Tp Thc Hnh s 2. (Thc hnh lp trnh vi m-file)


1) Thc hnh cc lnh trn ca s son tho m-file.
File-New : to tp tin mi, File-Open m tp tin c sn, File-Save lu tp tin lnh a,
File-Save as lu tp tin ln a vi mt tn khc.
2) Lp trnh vi m-file.
- Lp trnh vi Script m-file.
% Script m-file
t = 0:pi/100:2*pi;
x = 3 + 3*cos(t);
y = 2 + 3*sin(t);
plot(x,y), axis(square),grid;
- Lp trnh vi function m-file.
% Function m-file
function [x1, x2] = quadratic(a,b,c)
x = roots([a b c]);
x1 = x(1)
x2 = x(2)
%End
3) Thc hnh vi cc lnh nhp xut d liu input v disp trong Script v
function m-file.
4) Thc hnh vi cc lnh ca cu trc iu khin trong Script v function mfile.
Vng lp for, vng lp while, lnh r nhnh if, if-else, if-elseif-else, lnh kim tra
trng hp case, lnh break, .
5) Thc hnh hm chnh, hm con v hm ring (private function).
6) Thc hnh cc hm x l chui.
Double, char, strcmp, strcat, letter, ispace, int2str, num2str.
Thc hnh mng cu trc trn ca s lnh.
To mng cu trc bng ni dung v ch s.
Truy cp mng cu trc bng ni dung v ch s.
To mng cu trc bng lnh struct, gn gi tr ca trng tn cho bin dng lnh
getfield, thit lp mt gi tr khc cho trng tn dng lnh setfield, hy b trng
tn dng lnh rmfield.
- Lp trnh ng dng m-file vi mng cu trc.
8) Mng cell.
- To mng cell bng ni dung v ch s.
- Truy cp mng cell bng ni dung v ch s.
- Lp trnh ng dng m-file vi mng cell.
===================Ht Bi Tp Thc Hnh S 2 =================
7)
-

http://chunguv.blogspot.com

Bi Tp Thc Hnh S 3 : (X l ha )
1) X l ha hai chiu.
- Hm v th hai chiu plot(x,y, s), trong y l vect im v theo vect im
x, s l chui k t k hiu thit lp mu t v nt v.
- Hm xlabel to nhn trn trc ta x v hm ylabel to nhn trn trc ta y,
grid to mng k li, hold on/off.
- HHHm tilte to tiu th v hm legend to nhn cc th tng trn ca
s hnh.
- Hm axis([Xmin Xmax Ymin Ymax]) thit lp ta nh nht v ln nht trn
trc ta X-Y.
- Hm subplot(m,n,p) chi khung hnh figure ra nhiu khung con, trong mi
khung cha mt th vi m l s khung theo dng, n l s khung theo ct, p l s
th t ca cc khung c thit lp.
- To nt v khc nhau dng, mu v khc nhau.
- V th ng vect im y bm theo vect im x trn trc ta X-Y.
- Ly thuc tnh v thit lp thuc tnh cho i tng ha.
+ Hm get(h,property_name) ly thuc tnh.
+ Hm set(h,property_name) thit lp thuc tnh.
- Thc hnh hm fill, text v bar.
2) X l ha ba chiu.
- Hm plot3(x,y,z,s), trong x,y, z l cc vector im, s l chui k hiu cho mu
v nt v.
- Hm [x,y] = meshgrid(x,y) to hai vector im x, y kt hp v th ba chiu vi
hm surf(x,y,z,c) v mesh(x,y,z,c).
- Hm surfc, lnh view, contour, v clabel, colormap, shading
- Lnh movie v moviein.
- Hm sphere(N) v hnh cu, cylinder(r,n) v hnh tr.
3) Thc hnh to ca s giao din.
- To c s giao din dng c php lnh ca Matlab.
+Lnhfigure(property_name,property_value, . . .) to mn hnh ca s chnh.

http://chunguv.blogspot.com
+ Lnh axes(property_name, property_value, . . .) to h trc ta .

+ Lnh uicontrol(property_name, property_value, . . .) to nt iu khin giao


din.

http://chunguv.blogspot.com
+ Lnh uimenu(property_name, property_value, . . .) to h thng thc n giao
din.

- To giao din ngi s dng s dng cng c Guide.


G lnh guide trc du nhc ca ca s lnh, mn hnh chnh ca guide xut hin

=================Ht Bi Tp Thc Hnh S 3===============


6

http://chunguv.blogspot.com

Bi Tp Thc Hnh S 4 : ( S dng cc hm ton hc trong chuyn ngnh k


thut ).
1) Gii h phng trnh tuyn tnh thc v phc, nh thc, tr ring v vector ring,
thit lp cc h s ca a thc t ma trn c tnh.
2) Thc hnh to cc biu thc ca cc ton hc.
3) Thc hnh s dng cc hm ton hc ly tch phn xc nh mt bin, hai bin, ba
bin dng hm quad, dblquad, triplequad
4) Thc hnh gii cc h phng trnh vi phn bc mt dng hm ode23 v ode45
bin thin theo thi gian v v th p ng bin thin theo thi gian.
d

dt y (t ) v(t )

f (t )
2

v
(
t
)

y
(
t
)
v(t )
n
n

dt
m

http://chunguv.blogspot.com
5) Thc hnh vi hm ni suy mt chiu v ni suy hai chiu dng hm interp1 v
interp2, v th ni suy.

6) Thc hnh lp trnh ng dng vi bi ton v qi o chuyn ng ca cc hnh


tinh theo h mt tri.

http://chunguv.blogspot.com
Cc hnh tinh chuyn ng theo qu o elipse nh hnh

C + d = constant
d
c
f
f = ea

2b

2a
f2 = a2 b2
Tm v tr gc cui cng ca cc hnh tinh chuyn ng quanh h mt tri bng cc
gii cc phng trnh ton hc sau :

Kepler ( final )

A t
0
ab T

final

1
2
r
(

)
d

2 start

ab

t Final t Start
0
Period

a(1 ee ' )
r ( )
1 e cos( angle )
9

http://chunguv.blogspot.com
D liu ca cc hnh tinh chuyn ng theo h mt tri cho l
- Tn cc hnh tinh.
Name :
Mercury
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Neptune
Pluto
- Chu k chuyn ng ca cc hnh tinh theo h mt tri.
Periods :
Mercury = 0.24
Venus = 0.62
Earth = 1.00
Mars = 1.88
Jupititer = 11.86
Saturn = 29.46
Uranus = 84.00
Neptune = 164.8
Pluto = 247.7
- Qu o chuyn ng ca cc hnh tinh theo h mt tri.
Orbit :
Mercury = [0.39, 0.06]
Venus = [0.72, 0.007]
Earth = [1.00, 0.]
Mars = [1.52, 0.93]
Jupiter = [5.20, 0.048]
Saturn = [9.54, 0.056]
Uranus = [19.19, 0.047]
Neptune = [30.07, 0.009]
Pluto = [39.46, 0.249]
- Thi gian v gc bt u chuyn ng.
Start_t = 1995.0 + 3/365
Start_th (gc theta) :
Mercury = 345.7083
Venus = 138.8194
Earth = 102.1532
Mars = 119.2770
Jupiter = 242.7067
Saturn = 348.7888
Uranus = 291.6482
10

http://chunguv.blogspot.com

Neptune = 293.7496
Pluto = 231.6706
Lp trnh v cc qu o chuyn ng ca cc hnh tinh theo h mt tri vi khai
bo cu trc d liu theo ch s mng.
Lp trnh v cc qu o chuyn ng ca cc hnh tinh theo h mt tri vi khai
bo d liu theo mng cu trc.
==================Ht Bi Tp Thc Hnh S 4==================

11

http://chunguv.blogspot.com

Bi Tp Thc Hnh S 5 : (Simulink ng dng trong cc ngnh k thut ).


1) Thc hin cc thao tc trn mn hnh chnh ca simulink.

2) Thc hin cc thao tc trn mn hnh son tho m hnh.


3) Son tho cc khi chc trong ca s m hnh.
4) Xy dng m hnh gii cc h phng trnh vi phn vi hm truyn ng c DC.

12

http://chunguv.blogspot.com
5) Xy dng cc S m-file function.
- Three Time function.

ng c DC.

6) Lp trnh m-file s dng hm sim thit lp ng ra bin thin theo thi gian v
p ng ca m hnh.
========================Ht Bi Tp S 5=======================

13

http://chunguv.blogspot.com

Bi Tp Thc Hnh S 6 : (Nhp, xut, lu, np v truyn thng d liu qua


cng v card)
1)
2)
3)
4)
5)

Thc hnh cc lnh lu, np save, load v textread.


Thc hnh cc lnh nhp xut mc thp.
M file fopen.
c file fread.
Ghi file fwrite.
ng file fclose.
c v ct d liu dng hm fscanf v fprintf.
S dng hm fgetl v fgets.
Nhp xut qua cng ni tip.
Nhp xut qua cng my in.
Nhp xut qua card giao tip.
====================Ht Bi Thc Hnh S 6================

Bn c th download ti liu ny v t blog:


http://chunguv.blogspot.com
Website cung cp y ebook v : acad, 3dsmax, etabs, sap2000, ms
project, photoshop..
Ghi ch:
Chng ti khng chu trch nhim v bn quyn ca ti liu c pht
hnh.
Tt c ti liu do chng ti pht hnh u c ngun gc r rng v c
chn lc mt cch kht khe mang li cho bn c nhng ti liu tt
nht.
Chc mi ngi thnh cng !

14