You are on page 1of 3

Cau 1:

a)
>> % Khai bien ban dau:
>> t=[0 8 14 18 22 27 38 41 50 62 66 72 76 82 93];
>> n=[0 5 30 50 100 201 502 905 1305 1508 2100 2700 3001.5 2999 3001];
>> % Ve cac diem do tren man hinh may tinh:
>> plot(t,n,'s')
b)
>> % Phuong trinh mo ta bang so lieu khi biet dang tong quat:
>> pt = polyfit(t,n,14)
c)
>> % Ve dac tinh mo ta so lieu ra man hinh:
>> y = polyval(pt,t);
>> plot(t,y,'-r')
>> grid on % Hien luoi toa do.
d)
>> % Tim gia tri lon nhat cua toc do:
>> nmax = max(y)
------------------------------------------------------
cau 2:
a)
File/New/M-File ---> tao file gptb2.m voi noi dung sau:
function gptb2
a = input('nhap gia tri a=');
b = input('nhap gia tri b=');
c = input('nhap gia tri c=');
syms x;
x = solve(a*x^2+b*x+c,'x');
x = eval(x) % convert x to real variable (from string)
---------
hoac : File/New/M-File ---> tao file giaipt.m voi noi dung sau:
function giaipt(a,b,c)
syms x;
x = solve(a*x^2+b*x+c);
x = eval(x) % convert x to real variable (from string)

Voi truong hop cu the, tai dau nhac cua MATLAB ta go: >> giaipt(1,-3,2)
----------------------------------------------------------
b)
>> syms a c d e x
>> f = a*x^5+c*x^2+d*x+e;
>> dhb1_theo_x = diff(f,x)
>> dhb1_theo_a = diff(f,a)
>> dhb2_theo_a = diff(f,x,2)
>> dhb2_theo_a = diff(f,a,2)
-------------
c)
>> g =f+b*x^4;
>> tpbd = int(g)
>> a=1;
>> b=2;
>> c=-3;
>> d=1;
>> e=1;
>> g = a*x^5 + b*x^4 + c*x^2 + d*x + e;
>> tpxd = int(g,0,20)
----------------------------------------
Cau 3:
a)
>> a = [ 2 -3 3 -1 -1; -1 2 2 -2 -1; 4 -1 2 -3 -1; 3 3 1 -2 1; 1 2 -3 -1 -1];
>> b = [0;0;1;6;-2];
x = a\b
b)
>> [x,y,z] = solve('x^2*y + x*y + z = 3','x*y^2-x*y-z = -1','x*y-x*y*z+z = 1')
-----------------------------------------
Cau 4:
a)
omega = 0.1:0.05:2*pi;
s = j*omega;
r = 1./7.373./s;
o = 1.6.*exp(-0.12.*s)./(0.663.*s+1).^3;
Wh = r.*o;
re = real (Wh);
im = imag (Wh);
plot(re,im,'r-')
-------
b)
>> r = tf(1,[7.373 0]);
>> [num,den] = pade(0.12,5); % xap xi thoi gian tre.
>> o = zpk([],[-1/0.663,-1/0.663,-1/0.663],1.6)*tf(num,den);
>> Wh = r*o;
>> Wk = feedback(Wh,1);
>> nyquist(Wh) % Ve dac tinh tan so bien do pha cua he ho.
>> step(Wk) % Ve dac tinh qua do cua he kin.
>> grid on
>> hold on
-----------------------------------------------
Cau 5:
function cau5
cau5.m
disp('Nhap so diem tung mon hoc ki truoc:');
a=input('diem mon ATNL=');
b=input('diem mon Chuyen de=');
c=input('diem mon THUD=');
d=input('diem mon HQNL=');
disp('nhap so hoc trinh cua tung mon:');
ta=input('so hoc trinh mon ATNL=');
tb=input('so hoc trinh mon Chuyen de=');
tc=input('so hoc trinh mon THUD=');
td=input('so hoc trinh mon HQNL=');
x = a*ta + b*tb + c*tc + d*td;
y = ta + tb + tc + tc;
disp(' Diem trung binh hoc ky = ')
dtb = x/y % diem trung binh hoc ky
diem = [a b c d];
disp('mon hoc co diem cao nhat = ')
dcn = max(diem)
disp('Mon hoc co diem thap nhat = ')
dtn = min(diem) % mon hoc co diem thap nhat
--------------------------------------------------
Cau 6:
function cau6
cau6.m
tvtb=input('Nhiet do dau vao tuabin tvtb = ');
if tvtb<440
disp('Bo dieu chinh hoi qua nhiet phai cai tao lai!');
elseif tvtb>455
disp('Bo dieu chinh hoi qua nhiet phai cai tao lai!');
elseif tvtb>=440 & tvtb<445
disp('Bo dieu chinh lam viec chap nhan duoc!');
else
disp('Bo dieu chinh lam viec tot!');
end
>> cau6
Nhiet do dau vao tuabin tvtb = 450
Bo dieu chinh lam viec tot
-----------------------------------------------------
Cau 7:
>> syms x
>> f = x^8 - x^6 + x^5 - 3*x^4 - x^2 - 6*x + 1;
% Tim cac diem khong cua ham so:
>> x = solve(f)

% Tim gia tri cuc tieu cua ham so trong khoang [0.2, 1.5]:
>> f = inline('x^8 - x^6 + x^5 - 3*x^4 - x^2 - 6*x + 1');
>> xmin = fminbnd(f,0.2,1.5)
--------------------------------------------------------

Cau 8:
File/New/M-File ---> tao file function8.m voi noi dung sau:
function f=funtion8(x)
%function8.m
f = [2*x(1)^4 + x(2)^4 - 2*x(1)^2 - 2*x(2)^2 + 4*sin(x(1)*x(2))];

% Go lenh trong cua so MATLAB:


>> a = [1 -1; 0 -1];
>> b = [0;-1];
>> options = optimset('fmincon');
>> options = optimset(options,'Display','final','LargeScale','off');
>> x0 = [2 0];

>> % Gia tri nho nhat cua ham fval tai x(1) v� x(2):
>> [x,fval] = fmincon('function8',x0,a,b,[],[],[],[],[],options)
-----------------------------------------------------------
http://www.kaspersky.com/kos/eng/partner/default/kavwebscan.html

You might also like