You are on page 1of 9

PHN I: CC LNH THNG DNG TRONG GII TCH CU LNH M T GII HN-O HM-TCH PHN LOI HM

limit( f ) lim( f , a) hoc lim( f , x, a) lim( f , x, a, ' left ') lim( f , x, a, ' right ') diff ( f ), diff ( f , x) diff ( f , x, n) , diff ( f , n)
int ( f ) int ( f , x ) int ( f , a, b ) , int ( f , x, a, b )
quad(f,a,b) rsums(f,a,b), rsums(f,[a,b])

lim f ( x )
x 0

symbolic symbolic symbolic symbolic symbolic , f= f(x) (srting) symbolic ,string symbolic, string symbolic, string inline, handle inline, handle,(2010 c thm symbolic) symbolic Symbolic

lim f ( x )
xa xa

lim f ( x ) lim f ( x )

xa+

df = f ( x ) (bin mc dx nh l x) dn f n = f ( ) ( x) n dx

f ( x)dx

a b

f ( x)dx f ( x)dx

taylor(f,n) taylor(f,n,x0) factorial(N) compose(f,g) compose(f,g,u,v) finverse(f)

Tng Riemman ca f trn [a, b], xut dng bar( th) k n 1 f ( ) ( 0) k x k! k =0

k =0

n 1

f(

k)

( x0 )

k!

( x x0 )

Tnh giai tha: N! f(g(x)) f(g(v) Tm hm ngc ca f f=sym(f(x)),g=sym(g(x)) f=sym(f(u)),g=sym(g(v)) Symbolic

TNH TON TRN BIU THC subs(f,x,a), subs(f,x,a)

f ( x) f (a)

Dng 1: symbolic, string Dng 2: mi hm

feval(f,a), feval(f,[a,b]) polyval(p,a) eval(biu thc s) simplify simple

f ( x) f (a)
Tnh gi tr ca a thc p ti a Tr v gi tr ca biu thc dng thp phn. Rt gn biu thc Vit biu thc dng ngn nht.

inline, handle (1)

pretty(f) solve(f(x)) solve(F,G) fsolve(f,x0) fzero(

Biu din f theo dng vit tay Gii pt f(x) = 0 Gii h pt f(x,y)=0,g(x,y)=0 Gii pt f(x) = 0 trong khu vc gn x0

Symbolic C th thay: F=f(x) F=f(x,y),G=g(x,y) handle

Tr v vector h s ca a thc theo th t bc cao n thp Tr v a thc c cc h poly2sym(a) s tng ng vi cc phn t ca vector a Tm gi tr nh nht trn [x,m]=fminbnd(f,a,b), [a,b] Gii phng trnh vi dsolve(pt1,pt2,k1,k2,bin) phn , h pt vi phn vi bin c ch ra. Nhp d liu s t bn input(Thng bo) phm vi thng bo nm trong . sym2poly(f) input(Thng bo,s) disp(string),disp(x) fprinf Nhp chui t bn phm.

a thc Vector hng handle C th thay : F=pt1,G=pt2

strfind(S,s) strcmp(S1,S2)

Xut chui hoc gi tr ra mn hnh. Ghi d liu vo file text hoc xut d liu ra mn Xem Help hnh Tm chui con s trong chui ln S, kt qu l S,s l cc chui k t. th t ca phn t u tin trong chui con. So snh hai chui (ging hay khc nhau)

char(x) num2str(a)

Chuyn bin x sang dng chui (string) Chuyn s a sang dng chui(string) V TH

x l mt symbolic (!) a l mt gi tr bng s

ezplot(x(t),y(t),[t1,t2]) ezplot(f,[a,b]) ezplot3(x(t),y(t),z(t),[t1,t2]) fplot(f,[a,b] plot(x,f,tnh cht) plot3(x(t),y(y),z(t),tnh cht) polar(phi,r) fill(X, Y, C) surf(x,y,z) surfc(x,y,z) mesh(x,y,z) meshgrid(x,y) set(gca,xtick,[x1,x2]) set(gca,ytick,[y1,y2]) xlabe(str), ylabel(str), zlabel(str) title(string) legend

V ng cong tham s vi t chy trn [t1,t2] V th hm f vi bin chy trn [a, b]. V c tham s 3D V th hm f vi bin chy trn [a, b]. V th ca f theo x, x l min c ch ra theo(2) Tnh cht (3) V c 3D dng im V ng cong trong ta cc T mu min ng kn vi honh , tung bin nm trong X, Y bangwg mu C V mt cong V mt cong vi ng mc V mt li To ma trn li t cc vector x,y nh cc gi tr t trn Ox nh cc gi tr t trn Oy Gn tn cho cc trc Ox, Oy,Oz Gn tn cho hnh Gn tn cho tng th trn hnh.

Symbolic,string,inline,handle Symbolic,string,inline,handle

m-file, handle, inline, string V im, tp hp im

R l hm theo phi, phi l min c ch ra trong(2)

Str l chui k t

(1) Khai bo cho hm inline: inline(f(x),x), v d: f = inline(sin(x),x); Khai bao cho hm handle: handle = @(danh sch i s, bin) biu thc nh ngha. V d : f = @ (x) sin(x)+x*cos(x) g=@ (x,y) sin(x+y)-x*y (2) Khai bo min chy ca x trong trng hp ny c 2 cch

a. x = linspace(a,b) hay x=linspace(a,b,n) (n im chia trn [a, b]). V d: x=linspace(-2,3) (trn [-2,3] c 100 im chia). x= linspace(-2,3,70)( trn [-2,3] c 70 im chia) b. x= a:d/n:b : trn don [a, b], s im chia c tnh t quy c : on c di d c chia thnh n dim V d: x = 0: 20/100:1 c ngha x thuc [0,1], on c di 20 c chia thnh 100 im. Vy mi on con di 1/5 v [0,1] c 5 on chia tng ng vi cc im: 0, 1/5, 2/5, 3/5, 4/5, 1. (3) Tnh cht bao gm (tra cu bng LineSpec) a. Line Style b. LineWidth c. Color d. Marker (Marker s th hin cc im chia) i. MarkerType ii. MarkerSize iii. MarkerFaceColor & MarkerEdgeColor C php: 1. plot(x,y, kiu ng v, LineWidth, gi tr, MarkerFaceColor, gi tr , MarkerEdgeColor, gi tr , MarkerSize, gi tr ) 2. Kiu ng v th hin theo th t LineStyleColorMarkerType. v d: - -mo; :rx; -bs. Nu ch chn Marker v khng chn Line Style th ch c marker xut hin trn th.

Line Style Specifiers


Specifier
-: -.

Line Style Solid line (default) Dashed line Dotted line Dash-dot line

Marker Specifiers
Specifier
+ o * . x 'square' or s 'diamond' or d ^ v > < 'pentagram' or p 'hexagram' or h

Marker Type Plus sign Circle Asterisk Point (see note below) Cross Square Diamond Upward-pointing triangle Downward-pointing triangle Right-pointing triangle Left-pointing triangle Five-pointed star (pentagram) Six-pointed star (hexagram)

Note The point (.) marker type does not change size when the specified value is less than 5.

Color Specifiers
Specifier
r g b

Color Red Green Blue

Specifier
c m y

Color Cyan Magenta Yellow

Specifier
k w

Color Black White

PHN 2: LP TRNH TRONG MATLAB (tm tt nhng vn cn thit nht) A. CC HM TON HC sin(x), cos(x), tan(x), asin(x), acos(x), atan(x), sinh(x), cosh(x) abs(x): tr tuyt i hoc modun ca x. sqrt(x): cn bc 2 ca x. exp(x): ex log(x): ln(x) log10(x): log10 (x) a^x: ax B. CU TRC IU KIN 1. Cu trc if a. if iu kin Nhm lnh end b. if iu kin Nhm lnh 1 else Nhm lnh 2 end c. if iu kin 1 Nhm lnh 1 elseif iu kin 2 Nhm lnh 2 else Nhm lnh 3 end 2. Cu trc switch case (p dng khi c nhiu iu kin tng ng vi nhiu nhm ln khc nhau) TRNG HP = dy k t hoc dy s (TRNG HP=[TH1 TH2 TH3]) switch TRNG HP case TH1 nhm lnh 1 case TH2 nhm lnh 2 case TH3 nhm lnh 3 . otherwise nhm lnh n end

V D Gii phng trnh bc 2: ax 2 + bx + c = 0 dng cu trc if a=input(nhap a:); b=input(nhap b:); c=input(nhap c:); delta =b^2-4*a*c; if delta >0 disp(Phuong trinh co 2 nghiem thuc phan biet:); x1=(-b+sqrt(delta))/(2*a) x2=(-b-sqrt(delta))/(2*a) elseif delta==0 Gii phng trnh bc 2: ax 2 + bx + c = 0 dng cu trc switch case a=input(nhap a:); b=input(nhap b:); c=input(nhap c:); delta =b^2-4*a*c; if delta >0 choice =1 elseif delta==0 else end switch choice case 1 disp(Phuong trinh co 2 nghiem thuc phan biet:); x1=(-b+sqrt(delta))/(2*a) x2=(-b-sqrt(delta))/(2*a) case 2 disp(Phuong trinh co nghiem kep:); x= -b/(2*a) case 3 disp(Phuong trinh co nghiem phuc:); x1=(-b+i*sqrt(-delta))/(2*a) x2=(-b-i*sqrt(delta))/(2*a) end choice=3 choice=2

disp(Phuong trinh co nghiem kep:); x= -b/(2*a) else % truong hop nay la delta < 0

disp(Phuong trinh co nghiem phuc:); x1=(-b+i*sqrt(-delta))/(2*a) x2=(-b-i*sqrt(-delta))/(2*a) end

C. CU TRC VNG LP (s dung khi nhm lnh c lp li nhiu ln) 1. Vng lp for (s dng khi bit s ln lp ti a) for i=m:k:n Nhm lnh end i l bin m, bt u i t m n n, k l bc nhy ca i. Nu khng c k, bc nhy mc nh l 1. Nu k < 0, i li t m v n (trng hp ny m<=n). 2. Vng lp while (s dng trong mi trng hp) while iu kin lp Nhm lnh end

Script M-file Khng s dng tham s u vo

Function M-file C th chp nhn tham s u vo

hoc u ra
Hot ng trn d liu ca

v tr tham s u ra.
Cc bin trong thn hm mc

workspace
Thng dng t ng thc

nh l cc b.
c tc dng m rng ngn ng

hin mt chui thao tc cn thit thc thi nhiu ln.


VD: gii pt bc 2 dng Funtion

MATLAB cho ng dng ca bn.

function X=ptbac2(a,b,c) %ptbac2(a,b,c) giai phuong trinh bac hai ax^2+bx+c=0. if nargin<3 error('Nhap thieu doi so a hoac b hoac c');end if a==0&& b==0 error('Phuong trinh cua ban nhap sai'); elseif a==0 X=-c/b; else delta=b^2-4*a*c; if delta>0 X(1)=(-b+sym(sqrt(delta)))/(2*a); X(2)=(-b-sym(sqrt(delta)))/(2*a); elseif delta==0 X=-b/(2*a); else X(1)=(-b+i*sym(sqrt(-delta)))/(2*a); X(2)=(-b-i*sym(sqrt(-delta)))/(2*a); end end end