Tải bản đầy đủ (.pdf) (44 trang)

các dạng bài tập và đề thi matlab ,lập trình c,đo lường

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (148.36 KB, 44 trang )

BÀI 1: QUÁ TRÌNH NGUỘI CỐC CAFE (BẬC 1)
function baitoan1
clear all;clc;close all;
T=dsolve('DT=-r*(T-Tp)','T(0)=T0','t');
fprintf('bieu thuc cua T theo t la: ');pretty(T);
syms Tp T0 r t
% T=Tp+(T0-Tp)*exp(-r*t);
ti=0:2:46;
Tcd=[82.3,78.5,74.3,70.7,67.6,65.0,62.5,60.1,58.1,56.1,54.3,52.8,51
.2,49.9,48.6,47.2,46.1,45.0,43.9,43.0,41.9,41.0,40.1,39.5];
Tcs=[68.8,64.8,62.1,59.9,57.7,55.9,53.9,52.3,50.8,49.5,48.1,46.8,45
.9,44.8,43.7,42.6,41.7,40.8,39.9,39.3,38.6,37.7,37.0,36.4];
plot(ti,Tcd,'*-r');hold on; grid on;
ylabel('nhiet do (do C)');xlabel('thoi gian(phut)');
title('qua trinh nguoi cua coc cafe den');
Td=subs(T,[Tp,T0],[17,82.3]);
funTd=inline(vectorize(Td),'r','t');
r0d=0.025;
rnd=lsqcurvefit(funTd,r0d,ti,Tcd);
fprintf('hang so nguoi la'),rnd
yyd=funTd(rnd,ti);
plot(ti,yyd,'+-b');
legend('duong thuc nghiem','duong ly thuyet');
%tim thoi gian khi coc cafe co nhiet do 50 va 30
Td=subs(Td,r,rnd);
fprintf('bieu thuc nhiet do T cua coc cafe theo thoi gian t
la:');pretty(Td);
figure(2);
ezplot(Td,[0 80]);grid on;
t50d=double(solve(Td-50));
fprintf('thoi gian de coc cafe co nhiet do 50do la: '),t50d


t30d=double(solve(Td-30));
fprintf('thoi gian de coc cafe co nhiet do 30do la: '),t30d
figure(3);
plot(ti,Tcs,'*-r');hold on;grid on;
ylabel('nhiet do (do C)');xlabel('thoi gian(phut)');
title('qua trinh nguoi cua coc cafe sua');
Ts=subs(T,[Tp,T0],[17,68.8]);
funTs=inline(vectorize(Ts),'r','t');
r0s=0.023;
rns=lsqcurvefit(funTs,r0s,ti,Tcs);
fprintf('hang so nguoi la'),rns
1


yys=funTs(rns,ti);
plot(ti,yys,'+-b');
legend('duong thuc nghiem','duong ly thuyet');
%tim thoi gian khi coc cafe co nhiet do 50 va 30
Ts=subs(Ts,r,rns);
fprintf('bieu thuc nhiet do T cua coc cafe theo thoi gian t
la:');pretty(Ts);
figure(4);
ezplot(Ts,[0 80]);grid on;
t50s=double(solve(Ts-50));
fprintf('thoi gian de coc cafe co nhiet do 50do la: '),t50s
t30s=double(solve(Ts-30));
fprintf('thoi gian de coc cafe co nhiet do 30do la: '),t30s
%
%
%

%
%
%
%
%
%
%
%
%
%
%
%
%

bieu thuc cua T theo t la:
Tp + exp(-r t) (-Tp + T0)
hang so nguoi la: rnd =0.0259
bieu thuc nhiet do T cua coc cafe theo thoi gian t la:
653
7471411333879989
17 + --- exp(- ------------------ t)
10
288230376151711744
thoi gian de coc cafe co nhiet do 50do la:t50d =26.3287
thoi gian de coc cafe co nhiet do 30do la:t30d = 62.2662
hang so nguoi la: rns = 0.0237
bieu thuc nhiet do T cua coc cafe theo thoi gian t la:
3415481214600901
17 + 259/5 exp(- ------------------ t)
144115188075855872

thoi gian de coc cafe co nhiet do 50do la: t50s =19.0249
thoi gian de coc cafe co nhiet do 30do la: t30s =58.3317

####DẠNG KHÁC
function baitoan1_2
clear all;clc;close all;
T=dsolve('DT=-r*(T-Tp)','T(0)=T0','t');
disp('bieu thuc nhiet do: T(t)=');pretty(T);
syms r T0 Tp t
ti=0:2:46;
while (1)
k=menu('hang so nguoi','cafe den','cafe sua','thoat');
switch k
case 1
Tcd=[82.3,78.5,74.3,70.7,67.6,65.0,62.5,60.1,58.1,56.1,54.3,52.8,51
.2,49.9,48.6,47.2,46.1,45.0,43.9,43.0,41.9,41.0,40.1,39.5];
2


figure(1);
plot(ti,Tcd,'r');hold on;grid on;
nr=input('cho gan dung ban dau r la: '); %0.025
Tcdt=subs(T,[r,T0,Tp],[nr,Tcd(1),17]);
Tcdt=subs(Tcdt,t,ti);
plot(ti,Tcdt,'b');
ylabel('nhiet do (do C)');xlabel('thoi gian(phut)');
title('qua trinh nguoi cua coc cafe den');
legend('duong thuc nghiem',['duong ly thuyet voi r =',
num2str(nr)]);hold off;
case 2

Tcs=[68.8,64.8,62.1,59.9,57.7,55.9,53.9,52.3,50.8,49.5,48.1,46.8,45
.9,44.8,43.7,42.6,41.7,40.8,39.9,39.3,38.6,37.7,37.0,36.4];
figure(2);
plot(ti,Tcs,'r');hold on;grid on;
nr=input('cho gan dung ban dau r la: '); %0.023
Tcst=subs(T,[r,T0,Tp],[nr,Tcs(1),17]);
Tcst=subs(Tcst,t,ti);
plot(ti,Tcst,'b');
ylabel('nhiet do (do C)');xlabel('thoi gian(phut)');
title('qua trinh nguoi cua coc cafe den');
legend('duong thuc nghiem',['duong ly thuyet voi r =',
num2str(nr)]);hold off;
case 3
break
end
end

BÀI 2: QUÁ TRÌNH NGUỘI CỐC CAFE (BẬC 2)
function baitoan2
clear all;clc;close all;
T=dsolve('DT=-r2*(T-Tp)^2-r1*(T-Tp)','T(0)=T0','t');
fprintf('bieu thuc cua T theo t la: ');pretty(T);
syms Tp T0 r1 r2 t
ti=0:2:46;
Tcd=[82.3,78.5,74.3,70.7,67.6,65.0,62.5,60.1,58.1,56.1,54.3,52.8,51
.2,49.9,48.6,47.2,46.1,45.0,43.9,43.0,41.9,41.0,40.1,39.5];
plot(ti,Tcd,'*-r');hold on; grid on;
ylabel('nhiet do (do C)');xlabel('thoi gian(phut)');
title('qua trinh nguoi cua coc cafe den');
Td=subs(T,{Tp,T0,r1,r2},{17,'a(1)','a(2)','a(3)'});

3


funTd=inline(vectorize(Td),'a','t');
r0d=[82.3 0.006 0.0004];
rnd=lsqcurvefit(funTd,r0d,ti,Tcd);
%fprintf('hang so nguoi la:'),r1=rnd(2),r2=rnd(3)
fprintf(['hang so nguoi r1= ',num2str(rnd(2)),' va r2=
',num2str(rnd(3)),'\n']);
yyd=funTd(rnd,ti);
plot(ti,yyd,'+-b');
legend('duong thuc nghiem','duong ly thuyet');
%tim thoi gian khi coc cafe co nhiet do 50 va 30
Td=subs(Td,{'a(1)','a(2)','a(3)'},{rnd(1),rnd(2),rnd(3)});
%fprintf('bieu thuc nhiet do T cua coc cafe theo thoi gian t
la:');pretty(Td);
fprintf(['bieu thu nhiet do T cua coc cafe theo thoi gian t la:
\n',char(vpa(Td,3)),'\n']);
figure(2);
ezplot(Td,[0 120]);grid on;
t50d=double(solve(Td-50));
fprintf('thoi gian de coc cafe co nhiet do 50do la: '),t50d
t30d=double(solve(Td-30));
fprintf('thoi gian de coc cafe co nhiet do 30do la: '),t30d
% bieu thuc cua T theo t la:
%
r1 - r2 Tp + T0 r2
%
r1 + Tp exp(t r1 + log(- ------------------)) - r2
Tp

%
Tp - T0
%
- ---------------------------------------------------%
r1 - r2 Tp + T0 r2
%
-exp(t r1 + log(- ------------------)) + r2
%
Tp - T0
% hang so nguoi r1= 0.0071874 va r2= 0.00042365
% bieu thu nhiet do T cua coc cafe theo thoi gian t la:
% (.147e-4-17.*exp(.719e-2*t-7.54))/(-1.*exp(.719e-2*t-7.54)+.424e3)
% thoi gian de coc cafe co nhiet do 50do la: t50d =25.6294
% thoi gian de coc cafe co nhiet do 30do la: t30d =84.1027

4


BÀI 3: PHÂN HỦY HẠT NHÂN

Kr

Br

Se

function baitoan3
clear all;clc;close all;
T1=14.8;T2=16.1;
% lamda1=log(2)/T1;lamda2=log(2)/T2;

% d1='DN1=-ld1*N1';
% d2='DN2=-ld2*N2+ld1*N1';
% d3='DN3=ld2*N2';
% d=[d1,',',d2,',',d3];
% dkbd='N1(0)=1,N2(0)=0,N3(0)=0';
% dsol=dsolve(d,dkbd,'t');
% syms ld1 ld2 t
% N1t=subs(dsol.N1,ld1,lamda1);
% N2t=subs(dsol.N2,[ld1,ld2],[lamda1,lamda2]);
% N3t=subs(dsol.N3,[ld1,ld2],[lamda1,lamda2]);
ld1=log(2)/T1;ld2=log(2)/T2;
d1='DN1=-ld1*N1';
d2='DN2=-ld2*N2+ld1*N1';
d3='DN3=ld2*N2';
d=[d1,',',d2,',',d3];
dkbd='N1(0)=1,N2(0)=0,N3(0)=0';
dsol=dsolve(d,dkbd,'t');
N1t=subs(dsol.N1);
N2t=subs(dsol.N2);
N3t=subs(dsol.N3);
% ti=0:2:200;
% N1ti=subs(N1t,t,ti);
% plot(ti,N1ti,'r');
ezplot(N1t,[0 200]);hold on;grid on;
h1=ezplot(N2t,[0 200]);set(h1,'color',[1 0 0]);
h2=ezplot(N3t,[0 200]);set(h2,'color',[0 1 0]);
title('qua trinh phan huy Kr');
legend('Kr','Br','Se');
ylabel('khoi luong (mg)');
xlabel('thoi gian (gio)');

%khi mBr max
[x0,y0]=ginput(1);
% n2ti=inline(['-1*(',vectorize(N2t),')'],'t');
n2ti=inline(vectorize(-N2t),'t');
[xn,yn]=fminsearch(n2ti,x0,optimset('display','off'));
fprintf(['Br co khoi luong lon nhat la m= ',num2str(-yn),' tai t=
',num2str(xn),'\n']);
%khi mBr=mKr
[x01,y01]=ginput(1);
5


n12ti=inline(vectorize(-N2t+N1t),'t');
[xn1,yn1]=fsolve(n12ti,x01,optimset('display','off'));
fprintf(['Br co khoi luong bang Kr tai t= ',num2str(xn1),' khi do
mBr= ',num2str(-n2ti(xn1)),'\n']);
%khi mBr=mSe
[x02,y02]=ginput(1);
n23ti=inline(vectorize(-N2t+N3t),'t');
[xn2,yn2]=fsolve(n23ti,x02,optimset('display','off'));
fprintf(['Br co khoi luong bang Se tai t= ',num2str(xn2),' khi do
mBr= ',num2str(-n2ti(xn2)),'\n']);
% Br co khoi luong lon nhat la m= 0.38347 tai t= 22.2634
% Br co khoi luong bang Kr tai t= 20.5336 khi do mBr= 0.38225
% Br co khoi luong bang Se tai t= 28.763 khi do mBr= 0.37

BÀI 4: PHÂN HỦY HẠT NHÂN THEO 2 NHÁNH
Rn
Rn


26%Po
74%At

Bi
Po

Pb
Pb

function baitoan4
clear all; clc; close all;
TRn=15; TPo207=5.7; TBi=30*365*24; TAt=7.2; TPo211=0.52/3600;
lRn=log(2)/TRn;lPo207=log(2)/TPo207;lBi=log(2)/TBi;lAt=log(2)/TAt;l
Po211=log(2)/TPo211;
f1='DNRn=-lRn*NRn';
f21='DNPo207=-lPo207*NPo207+26/100*lRn*NRn';
f31='DNBi=-lBi*NBi+lPo207*NPo207';
f22='DNAt=-lAt*NAt+74/100*lRn*NRn';
f32='DNPo211=-lPo211*NPo211+lAt*NAt';
f=[f1,',',f21,',',f31,',',f22,',',f32];
dkbd='NRn(0)=1, NPo207(0)=0, NBi(0)=0, NAt(0)=0, NPo211(0)=0';
dsol=dsolve(f,dkbd,'t');
NRnt=subs(dsol.NRn);
NPo207t=subs(dsol.NPo207);
NBit=subs(dsol.NBi);
NAtt=subs(dsol.NAt);
NPo211t=subs(dsol.NPo211);
NPbt=1-(NRnt+NPo207t+NBit+NAtt+NPo211t);
6



ti=linspace(0,100);
subplot(3,2,1);ezplot(NRnt,[0 100]);grid on;title('Rn');
subplot(3,2,3);ezplot(NPo207t,[0 100]);grid on;title('Po207');
subplot(3,2,5);ezplot(NBit,[0 300]);grid on;title('Bi');
subplot(3,2,2);ezplot(NAtt,[0 100]);grid on;title('At');
subplot(3,2,4);NPo211i=double(subs(NPo211t,'t',sym(ti)));plot(ti,NP
o211i);grid on;title('Po211');
subplot(3,2,6);NPbi=double(subs(NPbt,'t',sym(ti)));plot(ti,NPbi);gr
id on;title('Pb');
%thoi diem cac nguyen to At,Po211,Po207 va Bi co khoi luong cuc dai
NAti=inline(vectorize(-NAtt),'t');
[t0,m0]=ginput(1);
[tn,mn]=fminsearch(NAti,t0,optimset('display','off'));
fprintf(['At co khoi luong lon nhat la m= ',num2str(-mn),' tai t=
',num2str(tn),'\n']);
NPo211i=inline(vectorize(-NPo211t),'t');
[t01,m01]=ginput(1);
[tn1,mn1]=fminsearch(NPo211i,t01,optimset('display','off','tolfun',
1e-12,'tolx',1e-12));
%mn1=double(subs(NPo211i,'t',sym(tn1)));
mn1=NPo211i(tn1);
fprintf(['Po211 co khoi luong lon nhat la m= ',num2str(-mn1),' tai
t= ',num2str(tn1),'\n']);
NPo207i=inline(vectorize(-NPo207t),'t');
[t02,m02]=ginput(1);
[tn2,mn2]=fminsearch(NPo207i,t02,optimset('display','off'));
fprintf(['Po207 co khoi luong lon nhat la m= ',num2str(-mn2),' tai
t= ',num2str(tn2),'\n']);
NBii=inline(vectorize(-NBit),'t');

[t03,m03]=ginput(1);
[tn3,mn3]=fminsearch(NBii,t03,optimset('display','off'));
fprintf(['Bi co khoi luong lon nhat la m= ',num2str(-mn3),' tai t=
',num2str(tn3),'\n']);
%Thoi diem khi mPb=1/3mRn va mPb=2/3mRn
figure(2);
NPb13Rn=inline(vectorize(NPbt-1/3*NRnt),'t');
NPb13Rni=double(subs(NPbt,'t',sym(ti))-1/3*subs(NRnt,'t',sym(ti)));
plot(ti,NPb13Rni,'r');grid on;hold on;
[tn130,mn130]=ginput(1);
7


[tn13,mn13]=fsolve(NPb13Rn,tn130,optimset('display','off','tolfun',
1e-12,'tolx',1e-12));
mn13=double(subs(NPbt,'t',sym(tn13)));
fprintf(['Pb co khoi luong bang 1/3Rn tai t= ',num2str(tn13),' khi
do mPb= ',num2str(mn13),'\n']);
NPb23Rn=inline(vectorize(NPbt-2/3*NRnt),'t');
NPb23Rni=double(subs(NPbt,'t',sym(ti))-2/3*subs(NRnt,'t',sym(ti)));
plot(ti,NPb23Rni,'b');
[tn230,mn230]=ginput(1);
[tn23,mn23]=fsolve(NPb23Rn,tn230,optimset('display','off','tolfun',
1e-12,'tolx',1e-12));
mn23=double(subs(NPbt,'t',sym(tn23)));
fprintf(['Pb co khoi luong bang 2/3Rn tai t= ',num2str(tn23),' khi
do mPb= ',num2str(mn23),'\n']);
%
%
%

%
%
%

At co
Po211
Po207
Bi co
Pb co
Pb co

khoi luong lon nhat la m=
co khoi luong lon nhat la
co khoi luong lon nhat la
khoi luong lon nhat la m=
khoi luong bang 1/3Rn tai
khoi luong bang 2/3Rn tai

0.1804 tai t= 14.6616
m= NaN tai t= 13.2432
m= 0.054602 tai t= 12.8336
0.25985 tai t= 221.8078
t= 13.9401 khi do mPb= 0.17124
t= 19.2396 khi do mPb= 0.26222

BÀI 5: NÉM XIÊN VỚI

Fms = k.v

function baitoan5

clear;close all;clc;
m=0.1;h0=15;v0=30;alpha=pi/6;k=0.15;g=9.8;
f1='D2x=-k/m*Dx';
f2='D2y=-k/m*Dy-g';
f=[f1,',',f2];
int='x(0)=0,Dx(0)=v0*cos(alpha),y(0)=h0,Dy(0)=v0*sin(alpha)';
fs=dsolve(f,int,'t');
x=subs(fs.x,{'m','h0','v0','alpha','k','g'},{m,h0,v0,alpha,k,g});
y=subs(fs.y,{'m','h0','v0','alpha','k','g'},{m,h0,v0,alpha,k,g});
vx=diff(x);vy=diff(y);
subplot(2,2,1);ezplot(x,[0 4]);title('do thi x theo thoi
gian');grid on;
subplot(2,2,2);ezplot(y,[0 4]);title('do thi y theo thoi
gian');grid on;
subplot(2,2,3);ezplot(vx,[0 4]);title('do thi vx theo thoi
gian');grid on;
8


subplot(2,2,4);ezplot(vy,[0 4]);title('do thi vy theo thoi
gian');grid on;
figure(2);
ezplot(x,y);title('do thi quy dao');grid on;
axis([0 20 0 25]);
%khi co ma sat vat di xa duoc xn
tn=double(solve([char(y),'=0'],'t'));tn=tn(1,1);
xn=subs(x,'t',tn);
%khi khong co ma sat vat di xa duoc mot khoang la xn1
%thay doi lai cac dieu kien ban dau khi ko co ma sat
f11='D2x=0';

f21='D2y=-g';
ff=[f11,',',f21];
fs1=dsolve(ff,int,'t');
tn1=double(solve([char(subs(fs1.y,{'m','h0','v0','alpha','k','g'},{
m,h0,v0,alpha,k,g})),'=0'],'t'));
tn1=tn1(2,1);
xn1=subs(subs(fs1.x,{'m','h0','v0','alpha','k','g'},{m,h0,v0,alpha,
k,g}),'t',tn1);
fprintf(['khi khong co ma sat vat se di xa them duoc mot khoang nua
la: ',num2str(xn1-xn),'m\n']);
%thoi diem va do cao vat dat do cao cuc dai
figure(1);
[t0,y0]=ginput(1);
yinl=inline(vectorize(-y),'t');
[tmax,ymax]=fminsearch(yinl,t0,optimset('display','off'));
fprintf(['do cao cuc dai cua vat la: h=',num2str(-ymax),'m',' tai
thoi diem: t= ',num2str(tmax),'s\n']);
%xac dinh goc nem toi uu de vat co the di xa nhat
fx=subs(fs.x,{'h0','m','v0','k','g'},{h0,m,v0,k,g});
fy=subs(fs.y,{'h0','m','v0','k','g'},{h0,m,v0,k,g});
phi=linspace(-pi/2,pi/2,20);
for i=1:length(phi)
fy1=subs(fy,'alpha',phi(i));
fx1=subs(fx,'alpha',phi(i));
t1=double(solve([char(fy1),'=0'],'t'));
for j=1:length(t1)
if t1(j)>0
tmax=t1(j);
end
end

9


xmax(i)=subs(fx1,'t',tmax);
end
sp=spline(phi,xmax);
figure(3);
fnplt(sp,[-pi/2 pi/2]);grid on;
figure(3);
[phi0,xmax0]=ginput(1);
[phin,xmaxn]=fminsearch(@(phi)ppval(sp,phi),phi0,optimset('display','off'));
fprintf(['goc nem toi uu la: phi= ',num2str(phin*180/pi),'do',' va
khi do xmax= ',num2str(-xmaxn),'m\n']);
% khi khong co ma sat vat se di xa them duoc mot khoang nua la:
82.8627m
% do cao cuc dai cua vat la: h=19.8052m tai thoi diem: t= 0.79515s
% goc nem toi uu la: phi= 2.5671do va khi do xmax= 19.7866m

BÀI 6: NÉM XIÊN VỚI Fms = k.v2
function baitoan6
clear all;close all;clc;
m=0.1; h0=15; v0=30; alpha=pi/6; g=9.8; vth=6; k=m*g/vth^2;
% u1=x;
% u2=y;
% u1'=u3=vx
% u2'=u4=vy
% u3'=-k/m*sqrt(u3^2+u4^2)*u3;
% u4'=-k/m*sqrt(u3^2+u4^2)*u4;
f=inline(['[u(3);u(4);',num2str(k/m),'*sqrt(u(3)^2+u(4)^2)*u(3);',...
num2str(-k/m),'*sqrt(u(3)^2+u(4)^2)*u(4)',num2str(g),']'],'t','u');

%odeset('abstol',1e-12,'reltol',1e-12);
[t,u]=ode45(f,[0 4],[0 h0 v0*cos(alpha) v0*sin(alpha)]);
%tim thoi diem vat tiep dat
sp=spline(t,u(:,2));
fnplt(sp,[0 4],'r');grid on;
[ty0 y0]=ginput(1);
[tn yn]=fsolve(@(t)ppval(sp,t),ty0,optimset('display','off'));
[t,u]=ode45(f,[0 tn],[0 h0 v0*cos(alpha) v0*sin(alpha)]);
plot(u(:,1),u(:,2),'r');grid on;title('do thi quy
dao');xlabel('x');ylabel('y');

10


figure(2);
subplot(2,2,1);plot(t,u(:,1));title('do thi x theo thoi gian');grid
on;xlabel('t');ylabel('x');
subplot(2,2,2);plot(t,u(:,2));title('do thi y theo thoi gian');grid
on;xlabel('t');ylabel('y');
subplot(2,2,3);plot(t,u(:,3));title('do thi vx theo thoi
gian');grid on;xlabel('t');ylabel('vx');
subplot(2,2,4);plot(t,u(:,4));title('do thi vy theo thoi
gian');grid on;xlabel('t');ylabel('vy');
%tinh khoang cach vat co the di xa them khi khong co ma sat
%khi khong co mat sat he ptvp se tra thanh
% u1=x;
% u2=y;
% u1'=u3=vx
% u2'=u4=vy
% u3'=0;

% u4'=-g;
f1=inline(['[u(3);u(4);0;-',num2str(g),']'],'t','u');
[t1,u1]=ode45(f1,[0 10],[0 h0 v0*cos(alpha) v0*sin(alpha)]);
sp1=spline(t1,u1(:,2));sp2=spline(t1,u1(:,1));
figure(3);
fnplt(sp1,[0 4],'r');grid on;
[ty01 y01]=ginput(1);
[tn1 yn1]=fsolve(@(t)ppval(sp1,t1),ty01,optimset('display','off'));
fprintf(['khi khong co ma sat vat se di xa them duoc mot khong nua
la: ',num2str(ppval(sp2,tn1)-u(end,1)),'m\n']);
%xac dinh thoi diem va vi tri vat o do cao cuc dai
figure(2);
[ty02 y02]=ginput(1);
[tn2 yn2]=fminsearch(@(t)ppval(sp,t),ty02,optimset('display','off'));
fprintf(['do cao cuc dai cua vat la:
h=',num2str(ppval(sp,tn2)),'m',' tai thoi diem: t=
',num2str(tn2),'s\n']);
%xac dinh goc nem toi uu de vat co the di xa nhat
phi=linspace(-pi/2,pi/2,20);
for i=1:length(phi)
[t2,u2]=ode45(f,[0 5],[0 h0 v0*cos(phi(i)) v0*sin(phi(i))]);
xmax(i)=u2(end,1);
end
sp3=spline(phi,xmax);
figure(3);fnplt(sp3,[phi(1) phi(end)],'r');grid on;
[phi0,xmax0]=ginput(1);
11


[phi,xmax]=fminsearch(@(phi)ppval(sp3,phi),phi0,optimset('display','off'));

fprintf(['goc nem toi uu la: phi= ',num2str(phi*180/pi),'do',' va
khi do xmax= ',num2str(-xmax),'m\n']);
% khi khong co ma sat vat se di xa them duoc mot khong nua la:
90.7651m
% do cao cuc dai cua vat la: h=17.2306m tai thoi diem: t= 0.51164s
% goc nem toi uu la: phi= 10.0363do va khi do xmax= 9.7807m

BÀI 7: NÉM BÓNG CHẠM TƯỜNG
function baitoan7
close all;clear;clc;
m=0.1;h0=10;v0=20;alpha=pi/6;l=15;k=0.1;g=9.8;
eqs=inline(['[y(3);y(4);-',num2str(k/m),'*y(3);-',num2str(k/m),...
'*y(4)-',num2str(g),']'],'t','y');
odeset('abstol',1e-12,'reltol',1e-12);
[t,y]=ode45(eqs,[0,3],[0 h0 v0*cos(alpha) v0*sin(alpha)]);
% Cau a:
spx=spline(t,y(:,1));
spy=spline(t,y(:,2));
figure(1);fnplt(spx,[0,3],'r');grid on;
[t0,x0]=ginput(1);
[t1,x1]=fsolve(@(t)(ppval(spx,t)-l),t0,optimset('display','off'));
h1=ppval(spy,t1);
fprintf(['Thoi diem qua bong cham tuong la: ',num2str(t1),...
's luc nay no co do cao: ',num2str(h1),'m \n']);
% Cau b:
figure(2);plot(t,y(:,2),'r');grid on;title('y(t)');
[t0,y0]=ginput(1);
[t2,x2]=fsolve(@(t)ppval(spy,t),t0,optimset('display','off'));
fprintf(['Thoi diem qua bong cham dat la: ',num2str(t2),...
's luc nay no cach tuong: ',num2str(ppval(spx,t2)-l),'m \n']);

[ti1,y1]=ode45(eqs,[0,t1],[0 h0 v0*cos(alpha) v0*sin(alpha)]);
[ti2,y2]=ode45(eqs,[t1,t2],[l h1 -y1(end,3) y1(end,4)]);
figure(3);
subplot(2,2,1);plot([ti1;ti2],[y1(:,1);y2(:,1)],'r');grid
on;title('x(t)');
subplot(2,2,2);plot([ti1;ti2],[y1(:,2);y2(:,2)],'r');grid
on;title('y(t)');
12


subplot(2,2,3);plot([ti1;ti2],[y1(:,3);y2(:,3)],'r');grid
on;title('vx(t)');
subplot(2,2,4);plot([ti1;ti2],[y1(:,4);y2(:,4)],'r');grid
on;title('vy(t)');
% Cau c:
Al=linspace(-pi/2,pi/2,10);
for i=1:length(Al)
[t,y]=ode45(eqs,[0,5],[0 h0 v0*cos(Al(i)) v0*sin(Al(i))]);
spx=spline(t,y(:,1));spy=spline(t,y(:,2));
%figure(4);fnplt(spy,[0,5],'r');grid on;
%[t0,y0]=ginput(1);
t0=4.5;
[tn,yn]=fsolve(@(t)ppval(spy,t),t0,optimset('display','off'));
xmax(i)=ppval(spx,tn);
end;
sp=spline(Al,xmax);figure(4);fnplt(sp,[-pi/2 pi/2],'r');grid on;
[Al0,xmax0]=ginput(1);
[Al,xmax]=fminsearch(@(Al)-ppval(sp,Al),Al0);xmax=-xmax-l;
fprintf(['Goc nem toi uu khi co ma sat la: ',num2str(Al*180/pi),...
'do, luc nay no cach tuong: ',num2str(xmax),'m \n']);

% Khi khong co ma sat:
eqs=inline(['[y(3);y(4);0;-',num2str(g),']'],'t','y');
Al=linspace(-pi/2,pi/2,10);
for i=1:length(Al)
[t,y]=ode45(eqs,[0,5],[0 h0 v0*cos(Al(i)) v0*sin(Al(i))]);
spx=spline(t,y(:,1));spy=spline(t,y(:,2));
%
figure(4);fnplt(spy,[0,5],'r');grid on;
%
[t0,y0]=ginput(1);
t0=4.5;
[tn,yn]=fsolve(@(t)ppval(spy,t),t0,optimset('display','off'));
xmax(i)=ppval(spx,tn);
end;
sp=spline(Al,xmax);figure(4);fnplt(sp,[-pi/2 pi/2],'r');grid on;
[Al0,xmax0]=ginput(1);
[Al,xmax]=fminsearch(@(Al)-ppval(sp,Al),Al0);xmax=-xmax-l;
fprintf(['Goc nem toi uu khi khong co ma sat la:
',num2str(Al*180/pi),...
'do, luc nay no cach tuong: ',num2str(xmax),'m \n']);
% Thoi diem qua bong cham tuong la: 2.0101s luc nay no co do cao:
7.4483m
% Thoi diem qua bong cham dat la: 2.9333s luc nay no cach tuong:
1.3987m
13


% Goc nem toi uu khi co ma sat la: 12.8022do, luc nay no cach
tuong: 2.6113m
% Goc nem toi uu khi khong co ma sat la: 39.3298do, luc nay no cach

tuong: 34.8036m

BÀI 8: TÊN LỬA PHÓNG THẲNG ĐỨNG
function baitoan8
clear all;close all;clc;
syms m vz ve g t dm dvz dt F Dz D2z Dm vth
dvz=D2z*dt;dm=Dm*dt;
F=-m*g-Dz*abs(Dz)*m*g/(vth^2);
p0=m*vz;
p1=(m+dm)*(vz+dvz)-dm*(vz-ve);
dp=p1-p0;
eq=dp/dt-F;
eq=simple(subs(eq));
%neu toc do chay cua nhien lieu là 5m/s
m=dsolve('Dm=-5','m(0)=100','t');Dm=diff(m,t);
t1=solve(m-10,t);t1=double(t1);
fprintf(['thoi gian de nhien lieu chay het
la:',num2str(t1),'s\n']);
% bieu thuc giai tich cua gia toc
a=solve(eq,D2z);a=limit(a,dt,0);
%fprintf(['bieu thuc giai tich cua gia toc la:',char(a),'\n']);
%khi ve=1000m/s; vth=100m/s; g=9.8 m/s^2
ve=1000;vth=100;g=9.8;
a1=subs(a);
a1=subs(a1,Dz,'h(2)');
eqs1=inline(['[','h(2)',';',char(a1),']'],'t','h');
[ti1,h1]=ode45(eqs1,[0,t1],[0 0]);
fprintf(['Do cao khi chay het nhien lieu la:
',num2str(h1(end,1)),'km \n']);
fprintf(['Van toc khi chay het nhien lieu la:

',num2str(h1(end,2)),'m/s\n']);
%sau khi nhien lieu chay het
m=10;Dm=0;
a2=subs(a);
a2=subs(a2,Dz,'h(2)');
eqs2=inline(['[','h(2)',';',char(a2),']'],'t','h');
[ti2,h2]=ode45(eqs2,[t1,120],[h1(end,1) h1(end,2)]);
sp=spline(ti2,h2(:,1));
%thoi diem cham dat và do cao cuc dai
14


tg=fsolve(@(ti2)ppval(ti2,sp),100,optimset('display','off'));
fprintf(['Thoi diem cham dat: ',num2str(tg),'s\n']);
[tmax,hmax]=fminsearch(@(ti2)-ppval(ti2,sp),32);
fprintf(['Do cao cuc dai: ',num2str(-hmax),'m\n']);
% Do thi:
fnplt(sp,[t1,tg],'b');hold on;grid on;
plot(ti1(end),h1(end,1),'ok',ti1,h1(:,1),'r');grid on;hold off;
text(ti1(end),h1(end,1),'Het nhien lieu');
%
%
%
%
%

thoi gian de nhien lieu chay het la:18s
Do cao khi chay het nhien lieu la: 4688.4344km
Van toc khi chay het nhien lieu la: 602.9548m/s
Thoi diem cham dat: 104.8246s

Do cao cuc dai: 6538.0025m

BÀI 9: TÊN LỬA PHÓNG NGHIÊNG GÓC 45 ĐỘ
function baitoan9
clear all;close all;clc;
syms m t v ve dm dt vx vy dvx dvy
syms F Fx Fy Dm D2x D2y vth g k
phi=pi/4;g=9.8;vth=100;ve=1000;v0=10;
k=10*g/(vth^2);v=sqrt(vx^2+vy^2);dvx=D2x*dt;dvy=D2y*dt;dm=Dm*dt;
Fx=-k*v*vx; Fy=-m*g-k*v*vy;
p1x=(m+dm)*(vx+dvx)-dm*(vx-ve*vx/v);p0x=m*vx;
p1y=(m+dm)*(vy+dvy)-dm*(vy-ve*vy/v);p0y=m*vy;
dpx=p1x-p0x;
dpy=p1y-p0y;
eqx=subs(dpx/dt-Fx);
eqy=subs(dpy/dt-Fy);
%khi nhien lieu chay voi toc do khong doi 5kg/s
m=dsolve('Dm=-5','m(0)=100','t');m=subs(m);
Dm=diff(m,t);Dm=subs(Dm);
tg=solve(m-10,t);tg=double(tg);
fprintf(['thoi gian chay het nhien lieu la: ',num2str(tg),'s \n']);
%bieu thuc giai tich cua a
ax=solve(eqx,D2x);ax=limit(ax,dt,0);
ay=solve(eqy,D2y);ay=limit(ay,dt,0);
% a=sqrt(ax^2+ay^2);a=simple(subs(a));
% fprintf(['bieu thuc giai tich cua gia toc: ',char(a),'\n']);
ax1=subs(ax);
ay1=subs(ay);
ax1=subs(ax1,{'vx','vy'},{'u(2)','u(4)'});
ay1=subs(ay1,{'vx','vy'},{'u(2)','u(4)'});

15


eqs=inline(['[','u(2)',';',char(ax1),';','u(4)',';',char(ay1),']'],
't','u');
[t1,u1]=ode45(eqs,[0 tg],[0 (v0*cos(phi)) 0 (v0*sin(phi))]);
fprintf(['tam xa khi chay het nhien lieu la:
',num2str(u1(end,1)),'m \n']);
fprintf(['do cao khi chay het nhien lieu la:
',num2str(u1(end,3)),'m \n']);
fprintf(['van toc khi chay het nhien lieu la:
',num2str(sqrt(u1(end,2)^2+u1(end,4)^2)),'m/s\n']);
%sau khi nhien lieu chay het
m=10;Dm=0;
ax2=subs(ax);
ay2=subs(ay);
ax2=subs(ax2,{'vx','vy'},{'u(2)','u(4)'});
ay2=subs(ay2,{'vx','vy'},{'u(2)','u(4)'});
eqs1=inline(['[','u(2)',';',char(ax2),';','u(4)',';',char(ay2),']']
,'t','u');
[t2,u2]=ode45(eqs1,[tg 31],[u1(end,1) u1(end,2) u1(end,3)
u1(end,4)]);
%thoi diem cham dat, vi tri cham dat va do cao cuc dai
plot([t1; t2],[u1(:,3); u2(:,3)]); grid on; hold on;
plot(t1(end),u1(end,3),'r*');
text(t1(end),u1(end,3),'Het nhien lieu');
spy=spline(t2,u2(:,3));
fun=@(t2)ppval(t2,spy);
[x0 y0]=ginput(1);
tg1=fsolve(fun,x0,optimset('display','off'));

fprintf(['thoi diem cham dat: ',num2str(tg1),'s \n']);
spy=spline(t1,u1(:,3));
fun1=@(t2)-ppval(t2,spy);
[x0 y0]=ginput(1);
[tmax,dc]=fminsearch(fun1,x0,optimset('display','off'));
fprintf(['do cao cuc dai: ',num2str(-dc),'m \n']);
spx=spline(t2,u2(:,1));
xcd=ppval(spx,tg1);
fprintf(['vi tri cham dat: ',num2str(xcd),'m \n']);
%hinh dong
figure(2);
t=[t1;t2];
x=[u1(:,1);u2(:,1)]; x=x(find(t<=tg1));
y=[u1(:,3);u2(:,3)]; y=y(find(t<=tg1));
h1=plot(x(1),y(1),'or');hold on;
h2=plot(x(1),y(1),'.r','markersize',30);
axis([0 12000 0 600]);
for k=1:length(x)
16


set(h1,'xdata',x(1:k),'ydata',y(1:k));
set(h2,'xdata',x(k),'ydata',y(k));
pause(0.1);
end;

%
%
%
%

%
%
%

thoi gian chay het nhien lieu la: 18s
tam xa khi chay het nhien lieu la: 7802.7089m
do cao khi chay het nhien lieu la: 544.4364m
van toc khi chay het nhien lieu la: 712.0285m/s
thoi diem cham dat: 30.7533s
do cao cuc dai: 582.4665m
vi tri cham dat: 10115.3337m

BÀI 10: CHUYỂN ĐỘNG CỦA HÀNH TINH
function baitoan10
clear all;close all;clc;
tn=5;
x0=1;y0=0.3;vx0=0.2;vy0=7;
eq=inline(['[u(2);','-4*pi^2*u(1)/(u(1)^2+u(3)^2)^(3/2);',...
'u(4);','-4*pi^2*u(3)/(u(1)^2+u(3)^2)^(3/2)]'],'t','u');
opt=odeset('reltol',1e-9,'abstol',1e-12);
[t,u]=ode45(eq,0:0.01:tn,[x0 vx0 y0 vy0],opt);
x=u(:,1);y=u(:,3);
vx=u(:,2); vy=u(:,4);
r=sqrt(x.^2+y.^2);
v=sqrt(vx.^2+vy.^2);
%chu ky
plot(t,x,'g',t,r,'r');title('do thi x(t),r(t)');grid
on;legend('x(t)','r(t)');
sp=spline(t,x);
[tn0 xn0]=ginput(2);

[tn1 xn1]=fsolve(@(t)ppval(sp,t),tn0,optimset('display','off'));
T=abs(tn1(1)-tn1(2));
fprintf(['chu ky: ',num2str(T),'year \n']);
%ban truc lon, ban truc nho
sp1=spline(t,r);
[t0min r0min]=ginput(1);
[tmin
rmin]=fminsearch(@(t)ppval(sp1,t),t0min,optimset('display','off'));
[t0max r0max]=ginput(1);
17


[tmax rmax]=fminsearch(@(t)ppval(sp1,t),t0max,optimset('display','off'));
rmax=-rmax;
a=(rmin+rmax)/2;
c=a-rmin;
b=sqrt(a^2-c^2);
fprintf(['ban truc lon la: ',num2str(a),' dvtv \n']);
fprintf(['ban truc nho la: ',num2str(b),' dvtv \n']);
%ve quy dao
figure(2);
plot(x,y,'r');
axis([-2 1.5 -1 2]);grid on;hold on;
plot(0,0,'.r','markersize',50);
% h1=plot(x(1),y(1),'ob');
h2=plot(x(1),y(1),'.b','markersize',30);
pause(0.1);
for i=1:length(x)
%
set(h1,'xdata',x(1:i),'ydata',y(1:i));

set(h2,'xdata',x(i),'ydata',y(i));pause(0.05);
end
%Kiem tra lai dinh luat Kepler III
x0kt=1;y0kt=0;vx0kt=0;vy0kt=5:.5:8;
for k=1:length(vy0kt)
[tkt,ukt]=ode45(eq,0:0.01:tn,[x0kt vx0kt y0kt vy0kt(k)],opt);
xkt=ukt(:,1);ykt=ukt(:,3);
rkt=sqrt(xkt.^2+ykt.^2);
figure(3);
plot(tkt,xkt,'g');title('do thi xkt(t)');grid on;
sp1=spline(tkt,xkt);
[tn01 xn01]=ginput(2);
[tn2
xn2]=fsolve(@(tkt)ppval(tkt,sp1),tn01,optimset('display','off'));
Tkt=abs(tn2(1)-tn2(2));
akt=(max(rkt)+min(rkt))/2;
Ts(k)=(Tkt^2)/(akt^3);
end
fprintf(['ket qua kiem tra ti so T^2/a^3 = \n',num2str(Ts),'\n']);
%
%
%
%
%

chu ky: 1.8094year
ban truc lon la: 1.4849 dvtv
ban truc nho la: 1.3459 dvtv
ket qua kiem tra ti so T^2/a^3 =
0.99998

0.99978
1
1
18

1

1

1


BÀI 11: CON LẮC ĐƠN
function baitoan11
close all;clear all;clc;
syms g l b
g0=9.8;l0=3;b1=0;b2=0.1/3;
eq='-g/l*sin(u(1))-b*l^2*abs(u(2))*u(2)';
%truong hop ko co ma sat
eq1=char(subs(eq,{g,l,b},{g0,l0,b1}));
eq1=inline(['[u(2);',eq1,']'],'t','u');
[t1,u1]=ode45(eq1,[0:0.05:30],[pi/3 0]);
teta1=u1(:,1);dteta1=u1(:,2);
x1=l0*sin(teta1);y1=l0*(1-cos(teta1));
Ed1=1./2*(l0*dteta1).^2;Et1=g0*l0*(1-cos(teta1));
E1=Ed1+Et1;
% truong hop co ma sat
eq2=char(subs(eq,{g,l,b},{g0,l0,b2}));
eq2=inline(['[u(2);',eq2,']'],'t','u');
[t2,u2]=ode45(eq2,[0:0.05:30],[pi/3 0]);

teta2=u2(:,1);dteta2=u2(:,2);
x2=l0*sin(teta2);y2=l0*(1-cos(teta2));
Ed2=1./2*(l0*dteta2).^2;Et2=g0*l0*(1-cos(teta2));
E2=Ed2+Et2;
%cac do thi
figure(1);
subplot(2,1,1);
plot(t1,teta1,t1,dteta1,'r');grid on;
legend('teta(t)','d(teta(t))/dt');
title('khi khong co ma sat - dao dong dieu hoa');
subplot(2,1,2);
plot(t2,teta2,t2,dteta2,'r');grid on;
legend('teta(t)','d(teta(t))/dt');
title('khi co ma sat - dao dong tat dan');
figure(2);
subplot(2,1,1);
plot(t1,Ed1,t1,Et1,'r',t1,E1,'g');grid on;
legend('dong nang (t)','the nang(t)','tong nang luong(t)');
title('khi khong co ma sat - nang luong bao toan');
subplot(2,1,2);
plot(t2,Ed2,t2,Et2,'r',t2,E2,'g');grid on;
legend('dong nang (t)','the nang(t)','tong nang luong(t)');
title('khi co ma sat - nang luong khong bao toan');
figure(3); %khong gian pha
plot(teta1,dteta1,teta2,dteta2,'r');grid on;
19


legend('khong co ma sat','co ma sat');
title('khong gian pha');

%su phu thuoc cua chu ki vao goc teta khi khong co ma sat
teta0=pi/18:pi/9:pi/2; u0=[teta0(:) zeros(size(teta0(:)))];
for k=1:length(teta0)
[t3,u3]=ode45(eq1,[0:0.05:10],u0(k,:));
teta3=u3(:,1);
figure(4);
plot(t3,teta3);grid on;
sp=spline(t3,teta3);
[t30 teta30]=ginput(2);
[t3n,teta3n]=fsolve(@(t3)ppval(sp,t3),t30,optimset('display','off')
);
T(k)=abs(t3n(1)-t3n(2));
end
fprintf('bang phu thuoc cua chu ky vao teta :\n');
disp([T(:) teta0(:)]);
Tb=2*pi*sqrt(l0/g0)*ones(size(teta0(:)));
figure(4);
plot(teta0,T,teta0,Tb,'r');grid on;title('su phu thuoc cua chu ky
vao teta');
legend('khi goc lon','khi goc be');xlabel('teta');ylabel('chu ky');
%hinh dong
figure(5);
plot([0,0],[l0 1.1*l0],'g','linewidth',10); %ve diem treo
title('khi khong co ma sat - dao dong tuan hoan');
hold on;axis equal;axis(l0*[-1.1 1.1 -1.1 1.1]);
h1=plot([0 x1(1)],[l0 y1(1)],'linewidth',2); %ve day treo
h2=plot(x1(1),y1(1),'.r','markersize',30);
%ve qua lac
pause(.4);
for k=1:length(x1)

x=[0 x1(k)];y=[l0 y1(k)];
set(h1,'xdata',x,'ydata',y);
set(h2,'xdata',x1(k),'ydata',y1(k));pause(0.03);
end
figure(6);
plot([0,0],[l0 1.1*l0],'k','linewidth',10);
title('khi co ma sat - dao dong tat dan');
hold on;axis equal;axis(l0*[-1.1 1.1 -1.1 1.1]);
h3=plot([0 x2(1)],[l0 y2(1)],'linewidth',2);
h4=plot(x2(1),y2(1),'.y','markersize',30);
pause(.4);
for k=1:length(x2)
x=[0 x2(k)];y=[l0 y2(k)];
20


set(h3,'xdata',x,'ydata',y);
set(h4,'xdata',x2(k),'ydata',y2(k));pause(0.03);
end
% bang phu thuoc cua chu ky vao teta :
%
3.4826
0.1745
%
3.5361
0.5236
%
3.6480
0.8727
%

3.8279
1.2217
%
4.1015
1.5708

BÀI 12: DAO ĐỘNG CƯỠNG BỨC
function baitoan12
close all;clear;clc;
syms x w0 w1 k t ti
w0=1.5;w1=1.9;k=0.2;ti=0:0.1:60;
sol=dsolve('D2x=-w0^2*x-k*Dx-cos(w1*t)','x(0)=0,Dx(0)=0','t');
x=subs(sol);xi=real(double(subs(x,t,ti)));
vx=diff(x,t);vxi=real(double(subs(vx,t,ti)));
Edi=1/2*vxi.^2;Eti=1/2*w0^2*xi.^2;
Ei=Edi+Eti;
figure(1);
plot(xi,vxi);grid on;
title('khong gian pha');
figure(2);
subplot(2,1,1);
plot(ti,Edi,ti,Eti,ti,Ei);grid on;
legend('Edi','Eti','Ei');
subplot(2,1,2);
plot(ti,xi,ti,vxi);grid on;
legend('xi(t)','vxi(t)');
%khi bien do on dinh
figure(3);
plot(ti,vxi);grid on;
title('van toc dao dong cuong buc theo thoi gian');

fvx=inline(vectorize(vx),'t');
[t0,v0]=ginput(1);
[tn,vn]=fsolve(fvx,t0,optimset('display','off'));
Atn=abs(double(subs(x,t,tn)));
Alt=1/sqrt((w1^2-w0^2)^2+k^2*w1^2);
disp('Bien do khi on dinh theo thuc nghiem va ly
thuyet');disp([Atn,Alt]);
%Su phu thuoc cua bien do dao dong khi on dinh vao tan so ngoai luc
w1
21


w12=1.2:0.1:1.8;
for i=1:length(w12)
w1=w12(i);
x=subs(sol);
xi=double(subs(x,t,ti));
vx=diff(x,t);
vxi=real(double(subs(vx,t,ti)));
figure(4);
plot(ti,vxi);grid on;
fvx=inline(vectorize(vx),'t');
[t0,v0]=ginput(1);
[tn,vn]=fsolve(fvx,t0,optimset('display','off'));
Atn(i)=abs(double(subs(x,t,tn)));
Alt(i)=1/sqrt((w1^2-w0^2)^2+k^2*w1^2);
end
disp('Bang phu thuoc A vao w1');
disp('
w1

thuc nghiem
ly thuyet');
disp([w12(:),Atn(:),Alt(:)]);
plot(w12(:),Atn(:),'-r+',w12(:),Alt(:),'-bo');
legend('thuc nghiem','ly thuyet');
% Bien do khi on dinh theo thuc nghiem va ly thuyet
%
0.6771
0.7082
%
% Bang phu thuoc A vao w1
%
w1
thuc nghiem ly thuyet
%
1.2000
1.1860
1.1837
%
1.3000
1.5715
1.6197
%
1.4000
2.5094
2.4807
%
1.5000
3.3037
3.3333

%
1.6000
2.2472
2.2445
%
1.7000
1.3949
1.3799
%
1.8000
0.9391
0.9493

BÀI 13: HỆ GỒM 50 DAO ĐỘNG TỬ TUYẾN TÍNH
function baitoan13
close all;clear all;clc;
global L k m we b uj vj j ti t1
L=50; m=1; k=1; we=1; b=0.1; j=1:L; ti=0:0.1:100;
u0=[zeros(size(j)) zeros(size(j))];
[t1,u1]=ode45('hpt_13',ti,u0);
uj=u1(:,1:2:2*L-1);
vj=u1(:,2:2:2*L);
l=[5 20 45];
22


for a=1:length(l)
subplot(3,1,a);
plot(ti,uj(:,l(a)),'-');grid on;
title(['li do cua dao dong tu thu ' num2str(l(a))]);

end
%%%%PHAN B:
figure(2);
tj=[5 20 100];
for i=1:length(tj)
n=find(ti==tj(i));
subplot(3,1,i);
plot(j,uj(n,:));
grid on;
title(['Li do cua he dao dong tai thoi diem t = ',
num2str(tj(i))]);
end

====================
function du=hpt_13(t,u)
global k m we b L
du(1)=u(2);du(2)=-k/m*(2*u(1)-u(3))-b*u(2)/m + 0.5*cos(we*t)/m;
for j=2:L-1
du(2*j-1)=u(2*j);
du(2*j)=-k/m*(2*u(2*j-1)-u(2*j-3)-u(2*j+1))-b*u(2*j)/m;
end
du(2*L-1)=u(2*L);
du(2*L)=-k/m*(2*u(2*L-1)-u(2*L-3))-b*u(2*L)/m;
du=du(:);

BÀI 14: NHIỄU XẠ
function baitoan14
clc;clear all;close all;
L=200;lm=600*1e-9;A=1;q=2*pi/lm;
while 1

k1=menu('Nhieu xa: ','n khe','lo tron','vanh tron','thoat');
switch k1
case 1%nhieu xa khe thuc
n=input('nhap so khe nhieu xa :')
D=5*lm;
a=25*lm;
q=2*pi/lm;
M=21;
d=D/(M-1);%chia moi khe thuc thanh nhieu khe nho
c=0;
y=-20:0.1:20;
23


yl=[-(n-1)/2:(n-1)/2].*a;
for nn=1:length(yl)
yk1=[-(M-1)/2:(M-1)/2].*d+repmat(yl(nn),1,M);
yk(:,nn)=yk1(:);
end;yk=yk(:);
rrk=inline('sqrt((y-yk).^2+L^2)','y','yk','L');
for k=1:length(yk)
c=c+A./rrk(y,yk(k),L).*exp(-i*q*rrk(y,yk(k),L));
end
I=abs(c.^2);
Imax=max(I);
I=I/Imax;
II=repmat(I,2,1);
figure;
subplot(2,1,1);
plot(y,I);

xlabel('mm');
subplot(2,1,2);
pcolor(y,1:2,II);
mau=gray;mau(:,[3])=0;
set(gcf,'colormap',mau);
shading interp;shg;xlabel('mm');
case 2 %Nhieu xa lo tron
R=5*lm;dn=R/50;
Rm=50;dm=Rm/100;
[xk,yk]=meshgrid(-R:dn:R);
xk=xk(:);
yk=yk(:);
k=find((xk.^2+yk.^2)xk=xk(k);
yk=yk(k);
rrk=inline('sqrt(yk.^2+(xxk).^2+L^2)','x','xk','yk','L');
x=0:dm:Rm;c=zeros(size(x));
for k=1:length(xk)
c=c+A./rrk(x,xk(k),yk(k),L).*exp(i*q*rrk(x,xk(k),yk(k),L));
end;
I=abs(c.^2);
Imax=max(I);
I=I/Imax;
II=[fliplr(I) I(2:end)];
figure;
x1=-Rm:dm:Rm;
plot(x1,II);
24



xlabel('mm');
[r,p]=meshgrid(0:dm:Rm,0:pi/30:2*pi);
x=r.*cos(p);
y=r.*sin(p);
I=repmat(I,size(x,1),1);
figure;pcolor(x,y,I);
mau=gray;
mau(:,[3])=0;
set(gcf,'colormap',mau);
shading interp;axis square;
case 3 % Vanh tron
R=7*lm;
dn=R/50;
Rm=50;
dm=Rm/100;
[xk,yk]=meshgrid(-R:dn:R);
xk=xk(:);
yk=yk(:);
k=find((((xk).^2+(yk).^2)<(7*lm)^2)&(((xk).^2+(yk).^2)>(5*lm)^2));
xk=xk(k);
yk=yk(k);
rrk=inline('sqrt(yk.^2+(xxk).^2+L^2)','x','xk','yk','L');
x=0:dm:Rm;c=zeros(size(x));
for k=1:length(xk)
c=c+A./rrk(x,xk(k),yk(k),L).*exp(i*q*rrk(x,xk(k),yk(k),L));
end;
I=abs(c.^2);
Imax=max(I);
I=I/Imax;
II=[fliplr(I) I(2:end)];

figure;
x1=-Rm:dm:Rm;
plot(x1,II);
xlabel('mm');
[r,p]=meshgrid(0:dm:Rm,0:pi/30:2*pi);
x=r.*cos(p);
y=r.*sin(p);
I=repmat(I,size(x,1),1);
figure;
pcolor(x,y,I);
mau=gray;
mau(:,[3])=0;
25


×