clc;clear all;close all; ti=0:2:46; % Thoi gian do Tps=17; % Nhiet do phong Ts=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; % Nhiet do thuc nghiem % Lap phuong trinh nguoi theo dinh luat nguoi thu I cua Newton T=dsolve(DT=r(TTp),T(0)=T0,t); % dsolve =>Tim no giai tich cua ptvp thuong % DT=dTdt % r : hang so nguoi % T : nhiet do cua vat % Tp : Nhiet do moi truong % t : thoi gian disp(Bieu thuc T tinh duoc: ); pretty(T) % pretty : Bieu dien dang tu nhien cua bien sym => lam dep syms r Tp T0 t % xac dinh hang so nguoi cua coc cafe bang tay(gan dung) % nr=input(nhap hang so nguoi r= ); %nhap r=0.025 % Tcf=subs(T,{r,Tp,T0},{nr,Tps,Ts(1)}) % Tcfi=double(subs(Tcf,t,ti)); % plot(ti,Ts,+r,ti,Tcfi) % sau khi tim r gan dung phu hop voi duong thuc nghiem % tim r bang pphap xap xi phi tuyen symT=subs(T,{Tp,T0,r},{Tps,a(1),a(2)}); %subs=>Tinh gtri cua DTDS T f=inline(vectorize(symT),a,t); % vectorize=>Chuyen phep tinh ma tran sang phep tinh vector an,dan=lsqcurvefit(f,Ts(1),0.02,ti,Ts); % lsqcurvefit=>Chinh xac hoa an T0=an(1); r=an(2); Tp=17; disp(hang so nguoi ); r % tim thoi diem coc cafe dat 30do,50do btT=vpa(subs(T),5); % vpa(x,n)=>Tinh gt T (bien sym) voi do chinh xac n=5 chu so thap phan disp(bieu thuc T(t): ); pretty(btT) t30=double(solve(btT30)) %double dung de dua gtri syms => so t50=double(solve(btT50)) % ve do thi T(t) cung so lieu thuc nghiem: tii=0:2:70; figure(2) plot(ti,Ts,+r,tii,double(f(an,tii))); grid on; End Hang so nguoi cua coc cafe la r=0.021529 Cong thuc cua ndo theo thoi gian la: T(t)= 17. + 49.084 exp(0.021529 t) Thoi gian khi coc cafe tro thanh 30 do la t= 61.7114 Thoi gian khi coc cafe tro thanh 50 do t= 18.4414 BÀI 2: Giả sử quá trình nguội của cốc cafe sữa tuân theo định luật nguội của Newton suy rộng: DT=r2(TTf)2 r1(TTf), Tf=17 độ. Xác định hằng số nguội r của cốc cafê Tìm biểu thức nhiệt độ của cốc cafê sữa T theo time t Vẽ đồ thị biểu thức T(t) cùng với số liệu trong bảng Xác định khi nào nhiệt độ của cốc cafê đạt 30 và 50 độ o0o clc;clear all;close all; ti=0:2:46; % Thoi gian do nTf=17; % Nhiet do phong Ti=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.8 47.2 ... 46.1 45.0 43.9 43.0 41.9 41.0 40.1 39.5; % Nhiet do thuc nghiem % lap phuong trinh nguoi theo dl suy rong cua Newton % r1, r2 : hang so nguoi cua T=dsolve(DT=r2(TTf)2r1(TTf),T(0)=T0,t); %dsolve=>Tim nghiem giai tich cua ptvp thuong disp(Bieu thuc T tinh duoc: ); pretty(T) % pretty : Bieu dien dang tu nhien cua bien sym syms r1 r2 Tf T0 t % tim r bang pphap xap xi phi tuyen symT=subs(T,{Tf,T0,r1,r2},{nTf,a(1),a(2),a(3)}); %subs=>Tinh gtri cua DTDS T f=inline(vectorize(symT),a,t); % vectorize=>Chuyen phep tinh ma tran sang phep tinh vector % Su dung dl I cua Newton de tim r1 sau do dung dl suy rong tim r2 a0=Ti(1),0.02,0; an,dan=lsqcurvefit(f,a0,ti,Ti); %Chinh xac hoa an T0=an(1); r1=an(2); r2=an(3); Tf=17; disp(hang so nguoi ); r1, r2 % Tim thoi diem coc cafe dat 30do,50do btT=vpa(subs(T),5); %vpa(x,n)=>Tinh gtrị T (biến sym) với độ cxac n (số chữ số thập phan) disp(bieu thuc T(t): ); pretty(btT) t30=double(solve(btT30)) t50=double(solve(btT50)) %ve do thi T(t) cung so lieu thuc nghiem: plot(ti,Ti,+r,ti,double(f(an,ti))); End Hang so nguoi cua coc cafe la r1= 0.0072 va r2= 4.2306e004 Cong thuc cua nhiet do theo thoi gian la: 0.000098876 + 0.59267 exp(0.0071936 t) 0.034863 exp(0.0071936 t) 0.027669 Thoi gian khi coc cafe tro thanh 30 do la t= 84.1375 Thoi gian khi coc cafe tro thanh 50 do t= 25.6440 CÁC BÀI TOÁN PHÂN HỦY HẠT NHÂN BÀI 3: Biết Kr phân hủy thành Br với thời gian bán rã T=14.8h. Br lại phân hủy thành Se với T=16.1h. Lúc đầu chỉ có 1mg Kr Khi nào Br có khối lượng lớn nhất và bằng bao nhiều? Khi nào Br có khối lượng bằng khối lượng Kr và bằng bao nhiều? Khi nào Br có khối lượng bằng khối lượng Se và bằng bao nhiều? o0o clc;clear all;close all; %Gan cac hang so ban ra va chu ky cua cac chat T12Kr=14.8; % Chu ky ban ra cua Kr T12Br=16.1; % Chu ky ban ra cua Br lKr=log(2)T12Kr; % hang so ban ra cua Kr (lamda=ln(2)T) lBr=log(2)T12Br; % hang so ban ra cua Br % Thiet lap ptvp (dNdt=lamdaN) % dN : So hat bi phan ra trong thoi gian dt % N : So hat con lai tai thoi dien t eq1=DNKr=lmKrNKr; % pt phan ra cua Kr, NKr ki hieu bien eq2=DNBr=lmKrNKrlmBrNBr; % pt phan ra cua Br eq3=DNSe=lmBrNBr; % pt phan ra cua Se eqs=eq1,,,eq2,,,eq3; % he pt phan ra int=NKr(0)=1,NBr(0)=0,NSe(0)=0; %dieu kien ban dau % Giai PT vi phan lay nghiem dsol=dsolve(eqs,int,t); %dsolve=>tim no gt cua ptvp: eqs, dkbd: int va bien doc lap: t syms lmKr lmBr t Kr=subs(dsol.NKr,{lmKr,lmBr},{lKr,lBr}); % lay nghiem NKr Br=subs(dsol.NBr,{lmKr,lmBr},{lKr,lBr}); Se=subs(dsol.NSe,{lmKr,lmBr},{lKr,lBr}); % Ve do thi bieu dien qua trinh phan ra theo thoi gian t fplot(char(Kr),0 200,r); hold on; fplot(char(Br),0 200,g); fplot(char(Se),0 200,:b); hold off; legend(Kr,Br,Se) % Xac dinh gia tri lon nhat cua Br dBr=diff(Br); %Tinh dao ham: disp(Thoi diem Br co khoi luong lon nhat: ); t1=double(solve(dBr)) disp(Khoi luong lon nhat cua Br la: ); Brmax=double(subs(Br,t,t1)) % Xac dinh thoi diem Br va Kr co khoi luong bang nhau: disp( Thoi diem Br va Kr co kl bang nhau : ); t2=double(solve(KrBr)) disp(khoi luong Kr va Br = ); mKr=double(subs(Kr,t,t2)) mBr=double(subs(Br,t,t2)) % Xac dinh thoi diem Br co khoi luong bang Se: t0,m0=ginput(1); t3,mSeBr=fsolve(inline(char(BrSe)),t0,optimset(display,off)); % fsolve=>chinh xac hoa nghiem gan dung t0 disp(Thoi diem Br co khoi luong bang Se: ); t3 disp(khoi luong Br va Se= ); mBr=double(subs(Br,t,t3)) mSe=double(subs(Se,t,t3)) End Nmax = 0.3835 Br co khoi luong lon khi: t = 22.2633h va bang : 0.38347mg Br co khoi luong bang Kr khi : t= 20.5336h va bang 0.3823mg Br co khoi luong bang Se khi : t= 28.7622h va bang 0.3700mg Bài 4: Biet Rn phan huy theo 2 cach( theo hinh ve) 211Rn>26%207Po>207Bi>207Pb 211Rn>74%At>211Po>207Pb o0o clc; clear all; close all; %Tinh cac hang so ban ra (h) TRn=15; LRn=log(2)TRn; %hang so ban ra cua Rn TAt=7.2; LAt=log(2)TAt; %hang so ban ra cua At TPo1=0.523600; LPo1=log(2)TPo1; %hang so ban ra cua Po211 TPo7=5.7; LPo7=log(2)TPo7; %hang so ban ra cua Po207 TBi=3036524; LBi=log(2)TBi; %hang so ban ra cua Bi % Thiet lap ptvp (dNdt=lamdaN) eq1=DNRn=LRnNRn; % pt phan ra cua Rn eq2=DNAt=LAtNAt+74100LRnNRn; %pt phan ra cua At eq3=DNPo1=LPo1NPo1+LAtNAt; %pt phan ra Po211 eq4=DNPo7=LPo7NPo7+26100LRnNRn; %phan ra ra 207Po eq5=DNBi=LBiNBi+LPo7NPo7; %PT phan ra 205Bi eq6=DNPb=LBiNBi+LPo1NPo1; %PT phan ra Pb eqs=eq1,,,eq2,,,eq3,,,eq4,,,eq5,,,eq6; % he pt phan ra int=NRn(0)=1,NAt(0)=0,NPo1(0)=0,NPo7(0)=0,NBi(0)=0,NPb(0)=0; % dieu kien ban dau % Giai PT vi phan lay nghiem sol=dsolve(eqs,int,t); %dsolve=>tim no gt cua ptvp: eqs, dkbd: int va bien doc lap: t
Trang 1BÀI 1: QUÁ TRÌNH NGUỘI CỐC CAFE (BẬC 1)
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');
legend('duong thuc nghiem','duong ly thuyet');
%tim thoi gian khi coc cafe co nhiet do 50 va 30
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');
Trang 2plot(ti,yys,'+-b');
legend('duong thuc nghiem','duong ly thuyet');
%tim thoi gian khi coc cafe co nhiet do 50 va 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
Trang 3figure(1);
plot(ti,Tcd,'r');hold on;grid on;
nr=input('cho gan dung ban dau r la: '); %0.025
figure(2);
plot(ti,Tcs,'r');hold on;grid on;
nr=input('cho gan dung ban dau r la: '); %0.023
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)'});
Trang 4r0d=[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
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
% -
(.147e-4-17.*exp(.719e-2*t-7.54))/(-1.*exp(.719e-2*t-7.54)+.424e-% 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
Trang 5
BÀI 3: PHÂN HỦY HẠT NHÂN Kr Br Se
Trang 6% 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
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;lPo211=log(2)/TPo211;
Trang 7subplot(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,NPo211i);grid on;title('Po211');
[tn130,mn130]=ginput(1);
Trang 8[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 khoi luong lon nhat la m= 0.1804 tai t= 14.6616
% Po211 co khoi luong lon nhat la m= NaN tai t= 13.2432
% Po207 co khoi luong lon nhat la m= 0.054602 tai t= 12.8336
% Bi co khoi luong lon nhat la m= 0.25985 tai t= 221.8078
% Pb co khoi luong bang 1/3Rn tai t= 13.9401 khi do mPb= 0.17124
% Pb co khoi luong bang 2/3Rn tai t= 19.2396 khi do mPb= 0.26222
BÀI 5: NÉM XIÊN VỚI Fms = k.v
subplot(2,2,1);ezplot(x,[0 4]);title('do thi x theo thoi
Trang 9subplot(2,2,4);ezplot(vy,[0 4]);title('do thi vy theo thoi
%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
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
Trang 10% 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
[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');
Trang 11%tinh khoang cach vat co the di xa them khi khong co ma sat
%khi khong co mat sat he ptvp se tra thanh
%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=
Trang 12% 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
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)]);
Trang 13'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
Trang 14% Goc nem toi uu khi co ma sat la: 12.8022do, luc nay no cach
Trang 15fnplt(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 ĐỘ
fprintf(['thoi gian chay het nhien lieu la: ',num2str(tg),'s \n']);
%bieu thuc giai tich cua a
Trang 16[t1,u1]=ode45(eqs,[0 tg],[0 (v0*cos(phi)) 0 (v0*sin(phi))]);
fprintf(['tam xa khi chay het nhien lieu la:
[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;
Trang 17% 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
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);
Trang 18fprintf(['ban truc lon la: ',num2str(a),' dvtv \n']);
fprintf(['ban truc nho la: ',num2str(b),' dvtv \n']);
%ve quy dao
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 1 1 1
Trang 19BÀI 11: CON LẮC ĐƠN
Trang 20legend('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(:)))];
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
title('khi co ma sat - dao dong tat dan');
hold on;axis equal;axis(l0*[-1.1 1.1 -1.1 1.1]);
Trang 22disp('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
Trang 23case 1%nhieu xa khe thuc
n=input('nhap so khe nhieu xa :')
Trang 24yl=[-(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
Trang 26clc;clear all;close all;
global delT tvc N delv Nvc m kb xyz vxyz
plot(T1,P1,'*r');grid on;hold off;
disp('Ap xuat trong binh khi T1=280:10:320');
disp(' Ly thuyet Thuc nghiem');
disp([P1(:),PT(:)]);
% Su phu thuoc cua ap suat khi L=0.08:.01:0.12;
L1=0.08:0.01:0.12;PL=apsuat(T,L1);hold on;
matdo2=N./((2*L1).^3);P2=matdo2.*kb.*T;%ap suat khi li tuong
plot(L1,P2,'*r');grid on;hold off;
disp('Ap xuat trong binh khi L1=0.08:0.01:0.12');
disp(' Ly thuyet Thuc nghiem');
disp([P2(:),PL(:)]);
% Do hoa dong:
% Vi tri ban dau ngau nhien:
xyz=-L+2*L*rand(1,3*N);phi=2*pi*rand(2,N);ph=phi(1,:);th=phi(2,:);figure;vxyz=v.*[cos(ph).*sin(th),sin(ph).*sin(th),cos(th)];
h=plot3(xyz(1:N),xyz(N+1:2*N),xyz(2*N+1:end),'.r','markersize',10);box on;grid on;
Trang 27[tvc,mol]=min(abs((xyz-L(k1)*sign(vxyz))./vxyz)); delT=delT+tvc;t(n)=delT;
Trang 28% Ap xuat trong binh khi T1=280:10:320
% Ly thuyet Thuc nghiem
% Ap xuat trong binh khi L1=0.08:0.01:0.12
% Ly thuyet Thuc nghiem
Trang 29hold on;
h2=plot(xx(1),yy(1),'.y');
set(h(1),'markersize',30);set(h(3),'markersize',30);set(h(5),'markersize',30);
Trang 30BÀI 17: CON LẮC KÉP
function baitoan17
close all;clear;clc;
syms l1 l2 m1 m2 g phi1 phi2 Dphi1 Dphi2 D2phi1 D2phi2
%phuong trinh lagrange
%giai phuong trinh lagrange d/dt(dL/dq.)-dL/dq=0
% 2 bac tu do la: q=[phi1 phi2]
dLq1=diff(L,Dphi1);
dLq2=diff(L,Dphi2);
pt1=diff(dLq1,phi1)*Dphi1+diff(dLq1,phi2)*Dphi2+diff(dLq1,Dphi1)*D2phi1+diff(dLq1,Dphi2)*D2phi2-diff(L,phi1);
pt2=diff(dLq2,phi1)*Dphi1+diff(dLq2,phi2)*Dphi2+diff(dLq2,Dphi1)*D2phi1+diff(dLq2,Dphi2)*D2phi2-diff(L,phi2);
Trang 31U=subs(U,{'phi1','phi2'},{phi1,phi2});
E=T+U;
subplot(3,1,1);
plot(t,phi1,t,phi2,'r');legend('phi1(t)','phi2(t)'); grid on;
title('do thi toa do phu thuoc thoi gian');
subplot(3,1,2); plot(t,Dphi1,t,Dphi2,'r');
legend('Dphi1(t)','Dphi2(t)');grid on;
title('do thi van toc phu thuoc thoi gian');
subplot(3,1,3); plot(t,T,t,U,'r',t,E,'g');legend('dong nang','the nang','tong nang luong');grid on;
title('do thi dong nang,the nang,nang luong phu thuoc thoi gian');
Trang 32BÀI 18: PHÂN HỦY HẠT NHÂN – PP MONTE CARLO
NKrph=NKr&(r1<lmKr); %so hat Kr bi phan huy thanh Br
NKr=NKr&(r1>lmKr); %so hat Kr chua bi phan huy
NBr=NBr&(r2>lmBr); %so hat Br chua bi phan huy
NBr=NBr|NKrph; %so hat Br bi phan huy thanh Se
niKr=nKr/Nthu; niKr=[N0 niKr];
niBr=nBr/Nthu; niBr=[0 niBr];
niSe=nSe/Nthu; niSe=[0 niSe];
%so hat tai cac thoi diem t tinh theo phuong phap giai tich
niKrgt=N0.*exp(-lmKr.*ti);
niBrgt=N0.*lmKr./(lmKr-lmBr).*(exp(-lmBr.*ti)-exp(-lmKr.*ti));
lmKr.*ti));
Trang 33legend('nKr_{mo phong}','nKr_{giai tich}','nBr_{mo
phong}','nBr_{giai tich}','nSe_{mo phong}','nSe_{giai tich}');
% So hat Kr bi phan huy trong mot don vi thoi gian tuan theo phan
Trang 35BÀI 20: GIAO THOA SÓNG
k=menu('song thanh phan','dang sine cung tan so,bien do',
'dang sine cung tan so,khac bien do','dang sine khac bien
do,khac tan so',
'dang xung gauss','thoat');
a1=0.5;a2=1;a3=1.5; %bien do song
%dang xung gauss
Trang 36h2=plot(x,u2);grid on; axis([x(1) x(end) -2.2 2.2]);title('song den');
u(nt+1,L)=2*(1-b)*u(nt,L)+b*(u(nt,L-1)+u(nt,1))-u(nt-1,L);
end
ut=[u(:,L),u,u(:,1)]; %vi u_0=u_L; u_1=u_L+1
Trang 37phi=gc+2*beta; %goc nem cua lan thu 2, sau khi qua bong cham dat
disp('lan cham dat thu nhat');
disp('thoi diem cham dat la:(s) ');disp(tc1);
disp('khi vat cach chan doc la:(m) ');disp(vtc1);
[t2,u2]=ode45(fu,[tc1 50],[xc1,vc1*cos(phi),yc1,vc1*sin(phi)]);x2=u2(:,1);y2=u2(:,3);vx2=u2(:,2);vy2=u2(:,4);
disp('lan cham dat thu hai');
disp('thoi diem cham dat la:(s) ');disp(tc2);
disp('khi vat cach chan doc la:(m) ');disp(vtc2);
[t3,u3]=ode45(fu,[0 tc1],[0,v0*cos(alpha),0,v0*sin(alpha)]);
x3=u3(:,1);y3=u3(:,3);
[t4,u4]=ode45(fu,[tc1 tc2],[xc1,vc1*cos(phi),yc1,vc1*sin(phi)]);x4=u4(:,1);y4=u4(:,3);
xi=[x3;x4];yi=[y3;y4];
figure(1);
Trang 38plot([0 xc1 xc2],[0 yc1 yc2]);hold on;
Trang 39disp('goc toi uu:(do) ');disp(g1*180/pi);
disp('khi do tam xa cuc dai la:(m) ');disp(-lm);
% lan cham dat thu nhat
% thoi diem cham dat la:(s)
% lan cham dat thu hai
% thoi diem cham dat la:(s)
Trang 40BÀI 22: NÉM XIÊN TRÚNG VẬT ĐANG RƠI
goc_alpha=double(solve(pt)); %tim alpha khi x2=x1=10,y2=y1
t0=subs(t0,'alpha',goc_alpha); %tim gia tri cu the cua t0
yc=subs(y1,t,t0);
fprintf(['khi khong co ma sat,hai vat se cham nhau khi goc nem alpha = ',num2str(goc_alpha*180/pi),' do \n']);
fprintf(['do cao khi va cham la: ',num2str(yc),' m \n']);
fprintf(['thoi diem khi va cham la: ',num2str(t0),' s \n']);
%khi luc ma sat ti le voi binh phuong van toc, he so ty le
goc=0:pi/100:pi/2; v0=20;
for i=1:length(goc)
al(i)=goc(i);
[t2,u2]=ode45(fu2,[0 2],[0;v0*cos(al(i));0;v0*sin(al(i))]); x2=spline(t2,u2(:,1)-10);
t0=fsolve(@(t2)ppval(x2,t2),1,optimset('display','off'));
Trang 41fprintf(['thoi diem khi va cham la: ',num2str(t02),' s \n']);
% khi khong co ma sat,hai vat se cham nhau khi goc nem alpha = 45
do
% do cao khi va cham la: 7.55 m
% thoi diem khi va cham la: 0.70711 s
% khi ko co ma sat, hai vat se va cham voi nhau khi goc alpha= 44.8792 do
% do cao khi va cham la: 7.4066 m
% thoi diem khi va cham la: 0.72908 s
ezplot(q12,[0 6]);grid on;
title('do thi ham q(t)');
Trang 42ezplot(q21,[0 20]);grid on;
Trang 43BÀI 24: CON LẮC ĐƠN TREO BẰNG LÒ XO
function baitoan24
close all;clear;clc;
syms m k L0 g r phi Dphi Dr D2phi D2r
%phuong trinh Lagrange
dLphi=diff(L,Dphi);
pt2=diff(dLphi,r)*Dr+diff(dLphi,Dr)*D2r+diff(dLphi,phi)*Dphi+diff(dLphi,Dphi)*D2phi-diff(L,phi);
Trang 44%ve quy dao