Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 50 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
50
Dung lượng
910 KB
Nội dung
CÁC BÀI TOÁN NGUỘI CỦA CỐC CAFE VD1: Xac dinh các tham so trong qua trinh nguoi cua coc cafe den bang phuong phap xap xi ham phi tuyen. Phuong trinh : dT/dt=-r(T-Tf) o0o % Gan so lieu clc;clear all;close all; ti=0:2:46; % Thoi gian do nTf=17; % Nhiet do phong 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 ]; % Nhiet do thuc nghiem % Giai phuong trinh nguoi T=dsolve('DT=-r*(T-Tf)','T(0)=T0','t'); disp('Bieu thuc T tinh duoc:'); pretty(T) %Tinh gia tri va ve do thi cua coc cafe den syms r t t0 T0 Tf nr=input('Nhap he so nguoi nr='); %nr=0.025 Tcdt=subs(T,{r,T0,Tf},{nr,Tcd(1),nTf}); ti1=0:2:50; Tcdt=subs(Tcdt,t,ti1); disp('Gia tri: ti Tcd Tcdt'); disp([ti;Tcd;Tcdt(1:24)]); figure(1); plot(ti1,Tcdt,' ',ti,Tcd,'r+'); title('Qua trinh nguoi cua coc cafe den'); xlabel('Thoi gian(phut)'); ylabel('Nhiet do (C)'); legend('So lieu tinh','So lieu do'); % End Bieu thuc T tinh duoc: Tf + exp(-r t) (T0 - Tf) Nhap he so nguoi nr=0.025 0 5 10 15 20 25 30 35 40 45 50 35 40 45 50 55 60 65 70 75 80 85 Qua trinh nguoi cua coc cafe den Thoi gian(phut) Nhiet do (C) So lieu tinh So lieu do VD2: Xac dinh cac tham so trong qua trinh nguoi cua coc cafe den bang xap xi ham phi tuyen. Phuong trinh : dT/dt=-r(T-Tf)^2 o0o % Gan so lieu clc;clear all;close all; ti=0:2:46; % Thoi gian do nTf=17; % Nhiet do phong 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 ]; % Nhiet do thuc nghiem % Giai phuong trinh nguoi T=dsolve('DT=-r*(T-Tf)^2','T(0)=T0','t'); %Tim no giai tich cua ptvp thuong disp('Bieu thuc T tinh duoc:'); pretty(T) %pretty:Bieu dien dang tu nhien cua bien sym 1 %Tinh gia tri va ve do thi cua coc cafe den syms r t t0 T0 Tf nr=input('Nhap he so nguoi nr='); %nr=0.0006; Tcdt=subs(T,{r,T0,Tf},{nr,Tcd(1),nTf}); %subs=>Tinh gtri cua DTDS khi biet bieu thuc T ti1=0:2:46; Tcdt=subs(Tcdt,t,ti1); disp('Gia tri: ti Tcd Tcdt'); disp([ti;Tcd;Tcdt(1:24)]); figure(1); plot(ti1,Tcdt,' ',ti,Tcd,'r+'); title('Qua trinh nguoi cua coc cafe den'); xlabel('Thoi gian(phut)'); ylabel('Nhiet do (C)'); legend('So lieu tinh','So lieu do'); % End Bieu thuc T tinh duoc: 2 r t Tf T0 - r t Tf + T0 r t T0 - r t Tf + 1 Nhap he so nguoi nr=0.0006 0 5 10 15 20 25 30 35 40 45 50 35 40 45 50 55 60 65 70 75 80 85 Qua trinh nguoi cua coc cafe den Thoi gian(phut) Nhiet do (C) So lieu tinh So lieu do VD3: Xac dinh cac tham so cua qua trinh nguoi bang xap xi ham phi tuyen. Phuong trinh : dT/dt=-r2(T-Tf)^2-r1(T-Tf). o0o % Gan so lieu clc;clear all;close all; ti=0:2:46; % Thoi gian do nTf=17; % Nhiet do phong 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 ]; % Nhiet do thuc nghiem % Giai phuong trinh nguoi T=dsolve('DT=-r(2)*(T-Tf)^2-r(1)*(T-Tf)','T(0)=T0','t'); disp('Bieu thuc T tinh duoc:'); pretty(T) %Tinh gia tri va ve do thi cua coc cafe den syms r1 r2 T12=subs(T,{'r(1)','r(2)'},{r1,r2}); disp('T12='); pretty(T12) T1=limit(T12,r2,0); disp('T1='); pretty(T1) 2 T2=limit(T12,r1,0); %Tinh gioi han cua T12 disp('T2='); pretty(T2) syms T0 Tf r t syf=subs(T,{'T0','Tf'},{82.3,nTf}); f=inline(vectorize(syf),'r','t'); r1201=[.025,0];r1202=[1e-12 .0006]; r12=lsqcurvefit(f,r1201,ti,Tcd) %Chinh xac hoa r12 figure(1); plot(ti,Tcd,'o',ti,(f(r1201,ti)),' '); title('Mo hinh dT/dt=-r_1.(T-Tf)'); xlabel('t-min'); ylabel('T (C)'); grid on; legend('So lieu tinh','So lieu do'); figure(2); plot(ti,Tcd,'o',ti,(f(r1202,ti)),' '); title('Mo hinh dT/dt=-r_2.(T-Tf)^2'); xlabel('t-min'); ylabel('T (C)'); grid on; legend('So lieu tinh','So lieu do'); figure(3); plot(ti,Tcd,'o',ti,(f(r12,ti)),' '); title('Mo hinh dT/dt=-r_1.(T-Tf)-r_2.(T-Tf)^2'); xlabel('t-min'); ylabel('T (C)'); grid on; legend('So lieu tinh','So lieu do'); % End r12 = 0.0074 0.0004 0 5 10 15 20 25 30 35 40 45 50 35 40 45 50 55 60 65 70 75 80 85 Mo hinh dT/dt=-r 1 .(T-Tf)-r 2 .(T-Tf) 2 t-min T (C) So lieu tinh So lieu do VD4: Xac dinh tham so bang ham lscurvefit theo pp xap xi ham phi tuyen o0o % Gan so lieu clc;clear;close all; ti=0:2:46; nTf=17; 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 ]; % Giai phuong trinh nguoi dT/dt=-r2(T-Tf) T=dsolve('DT=-r*(T-Tf)','T(0)=T0','t'); disp('Bieu thuc T tinh duoc:'); pretty(T) %Tinh gia tri va ve do thi cua coc cafe den syms r T0 Tf P t symf=subs(T,{'r' ,'T0','Tf'},{'P(1)','P(2)',nTf}); f=inline(vectorize(symf),'P','t'); P0=[0.2,Tcd(1)]; Pn=lsqcurvefit(f,P0,ti,Tcd); r=Pn(1);T0=Pn(2) figure(1); plot(ti,Tcd,'o',ti,(f(Pn,ti)),' '); 3 0 5 10 15 20 25 30 35 40 45 50 35 40 45 50 55 60 65 70 75 80 85 Mo hinh dT/dt=-r 1 .(T-Tf) t-min T (C) So lieu tinh So lieu do 0 5 10 15 20 25 30 35 40 45 50 35 40 45 50 55 60 65 70 75 80 85 Mo hinh dT/dt=-r 2 .(T-Tf) 2 t-min T (C) So lieu tinh So lieu do title('Mo hinh dT/dt=-r_1.(T-Tf)'); xlabel('t-min'); ylabel('T (C)'); grid on; legend('So lieu tinh','So lieu do'); % Giai phuong trinh nguoi dT/dt=-r2(T-Tf)^2 T=dsolve('DT=-r*(T-Tf)^2','T(0)=T0','t'); disp('Bieu thuc T tinh duoc:') pretty(T) %Tinh gia tri va ve do thi cua coc cafe den %syms r T0 Tf P t symf=subs(T,{'r','T0','Tf'},{'P(1)','P(2)',nTf}); f=inline(vectorize(symf),'P','t'); P0=[0.2,Tcd(1)]; Pn=lsqcurvefit(f,P0,ti,Tcd); r=Pn(1); T0=Pn(2) figure(2); plot(ti,Tcd,'o',ti,(f(Pn,ti)),' '); title('Mo hinh dT/dt=-r_2.(T-Tf)^2'); xlabel('t-min'); ylabel('T (C)'); grid on; legend('So lieu tinh','So lieu do'); % End 0 5 10 15 20 25 30 35 40 45 50 35 40 45 50 55 60 65 70 75 80 85 Mo hinh dT/dt=-r 2 .(T-Tf) 2 t-min T (C) So lieu tinh So lieu do 0 5 10 15 20 25 30 35 40 45 50 35 40 45 50 55 60 65 70 75 80 85 Mo hinh dT/dt=-r 1 .(T-Tf) t-min T (C) So lieu tinh So lieu do 4 CÁC BÀI TOÁN PHÂN HỦY HẠT NHÂN VD1: o0o function box1; close all; clc; N=1000; dt=N/10; t=0:10*N; % N-so hat trong hop n=zeros(size(t)); n(1)=N; %Tao mang co kich thuoc t co cac ptu =0 n_gt=N/2*(1+exp(-2*t/N)); plot(t,n_gt,t,N/2*ones(size(t))); ylim([N/4 N]); hold on; h=plot(1,N,'r'); legend('n_{giai tich}','N/2','n_{mo phong}'); shg; for k=1:length(t)-1; r=rand; p=n(k)/N; if r < p; n(k+1)=n(k)-1; else n(k+1)=n(k)+1; end; if mod(k,dt)==0 set(h,'xdata',t(1:k),'ydata',n(1:k)); pause(.01) end end; nn=n(5*N:10*N); m=mean(nn), s=std(nn), st=s/(N/2) % End 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 300 400 500 600 700 800 900 1000 n giai tich N/2 n mo phong VD2: o0o function nucdecay1; clc;clear all;close all; % Mo phong Monte-Callor quy luat phan huy hat nhan % theo phan bo Poisson. global ntrial; N0=500; % N0-So hat nhan khg ben luc dau p=0.01; % p-Xac suat phan huy ntrial=10000; % ntrial-So lan thu for k=1:ntrial % So hat bi phan huy sau 1 d/v thoi gian. N=ones(1,N0); r=rand(size(N)); N=N&(r>p); nn(k)=N0-sum(N); % So hat bi phan huy sau 2 d/v thoi gian. r=rand(size(N)); 5 N=N&(r>p); nn1(k)=N0-sum(N); end fnucdec(nn,1); fnucdec(nn1,2) % function fnucdec(nn,fig); global ntrial; figure(fig); n=0:max(nn); np=hist(nn,n); Pi=np/ntrial; %hist=>tinh tan so cua mau m=mean(nn); s2=var(nn); subplot(2,1,1); bar(n,np); xlim([0 n(end)]); title(['Tan so phan huy sau ', num2str(fig),' dvtg']); % Do thi tan suat. subplot(2,1,2); stem(n,Pi); % Tinh ham phan bo Poisson Plt=m.^n./factorial(n)*exp(-m); hold on; plot(n,Plt,'.r-'); hold off; title(['Phan bo Poisson voi < n > = ', num2str(m)]) % End 0 5 10 15 0 500 1000 1500 2000 Tan so phan huy sau 1 dvtg 0 5 10 15 0 0.05 0.1 0.15 0.2 Phan bo Poisson voi < n > = 5.0085 0 5 10 15 20 0 500 1000 1500 Tan so phan huy sau 2 dvtg 0 5 10 15 20 25 0 0.05 0.1 0.15 0.2 Phan bo Poisson voi < n > = 9.9415 VD3: Mo phong Monte-Callor phan huy hat nhan o0o clear; clc; close all; N0=10; % N0 -So hat nhan khong ben luc dau p=0.01; % p -Xac suat phan huy tmax=500; % tmax -Khoang thoi gian khao sat ntrial=200; % ntrial -So lan thu ti=1:tmax; ncum=zeros(1,tmax); for k=1:ntrial N=ones(1,N0); for t=1:tmax; r=rand(size(N)); N=N&(r>p); ncum(t)=ncum(t)+sum(N); end end ni=ncum/ntrial; ti=[0 ti]; ni=[N0 ni]; ni_gt=N0*exp(-p*ti); h=plot(ti(1),ni(1),'r',ti,ni_gt,'b'); legend('ni_{mo phong}','ni_{giai tich}'); 6 for k=1:length(ti); set(h(1),'xdata',ti(1:k),'ydata',ni(1:k)); pause(.01); end; % End 0 50 100 150 200 250 300 350 400 450 500 0 1 2 3 4 5 6 7 8 9 10 ni mo phong ni giai tich VD4: Mo phong Monte-Callor phan huy hat nhan me > con o0o clear; clc; close all; N0=5000; % -So hat nhan khong ben luc dau p1=0.01; % -Xac suat phan huy h/n ng/to 1 p2=0.005; % -Xac suat phan huy h/n ng/to 2 % tmax: -Khoang thoi gian khao sat % ntrial: -So lan thu tmax=1000; ntrial=1; ti=1:tmax; ncum1=zeros(1,tmax); ncum2=ncum1; for k=1:ntrial N1=ones(1,N0); N2=zeros(1,N0); for t=1:tmax; r1=rand(size(N1)); r2=rand(size(N2)); N3=N1&(r1<p1); % So hat nhan me bi phan huy N1=N1&(r1>p1); % So hat nhan me khong bi phan huy N2=N2&(r2>p2); % So hat con khong bi phan huy N2=N2|N3; ncum1(t)=ncum1(t)+sum(N1); ncum2(t)=ncum2(t)+sum(N2); end end ni1=ncum1/ntrial; ni2=ncum2/ntrial; ti=[0 ti]; ni1=[N0 ni1]; ni2=[0 ni2]; ni1_gt=N0*exp(-p1*ti); ni2_gt=N0/(p1-p2)*p1*exp(-p2*ti) -N0/(p1-p2)*p1*exp(-p1*ti); plot(ti,ni1,ti,ni1_gt,ti,ni2,ti,ni2_gt); legend('n1i_{mphong}','n1i_{gtich}', 'n2i_{mphong}','n2i_{gtich}'); % End 0 100 200 300 400 500 600 700 800 900 1000 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 n1i mphong n1i gtich n2i mphong n2i gtich 7 VD5: Mo phong Monte-Callor quy luat phan huy hat nhan Theo quy luat ham mu. o0o clc; close all; N0=2000; % N0-So hat nhan khg ben luc dau p=0.01; % p-Xac suat phan huy tmax=200; % khoang thoi gian quan sat ntrial=1; % ntrial-So lan thu ti=1:tmax; ncum=zeros(1,tmax); for k=1:ntrial N=ones(1,N0); for t=1:tmax r=rand(size(N)); N=N&(r>p); ncum(t)=ncum(t)+sum(N); end end ni=ncum/ntrial; ti=[0 ti]; ni=[N0 ni]; ni_gt=N0*exp(-p*ti); %Cong thuc giai tich h=plot(ti(1),ni(1),'r',ti,ni_gt,'b'); legend('ni_{mo phong}','ni_{giai tich}'); for k=1:length(ti) set(h(1),'xdata',ti(1:k),'ydata',ni(1:k)); pause(.01); end; % End 0 20 40 60 80 100 120 140 160 180 200 200 400 600 800 1000 1200 1400 1600 1800 2000 ni mo phong ni giai tich VD6: Mo phong Monte-Callor quy luat phan huy hat nhan Ngto pxa 1(me) > ngto pxa 2(con). Khi bi pra >ngto ben vung o0o clc; close all; close all; N0=2000; % N0-So hat nhan khg ben luc dau p1=0.01; % Xac suat phan huy hat nhan gto 1(me) p2=0.005; % Xac suat phan huy hat nhan gto 2(con) tmax=500; % khoang thoi gian quan sat ntrial=1; % ntrial-So lan thu ti=1:tmax; ncum1=zeros(1,tmax); ncum2=ncum1; for k=1:ntrial N1=ones(1,N0); N2=zeros(1,N0); for t=1:tmax r1=rand(size(N1)); r2=rand(size(N2)); N3=N1&(r1<=p1); %So hat nhan me bi phan huy thanh hat nhan con N1=N1&(r1>p1); %So hat nhan me ko bi phan huy thanh hat nhan con N2=N2&(r2>p2); %So hat nhan con ko bi phan huy 8 N2=N2|N3; ncum1(t)=ncum1(t)+sum(N1); ncum2(t)=ncum2(t)+sum(N2); end end ni1=ncum1/ntrial; ni2=ncum2/ntrial; ti=[0 ti]; ni1=[N0 ni1];ni2=[N0 ni2]; ni1_gt=N0*exp(-p1*ti); %Cong thuc giai tich ni2_gt=N0/(p1-p2)*p1*exp(-p2*ti)-N0/(p1-p2)*p1*exp(-p1*ti); plot(ti,ni1,'r',ti,ni1_gt,'b',ti,ni2,'k',ti,ni2_gt,'g'); legend('n1i_{mo phong}','n1i_{giai tich}','n2i_{mo phong}','n2i_{giai tich}'); % End 0 50 100 150 200 250 300 350 400 450 500 0 200 400 600 800 1000 1200 1400 1600 1800 2000 n1i mo phong n1i giai tich n2i mo phong n2i giai tich VD7: Phan ra phong xa Kr > Br > Se o0o clc;clear;close all T12Kr=14.8; T12Br=16.1; lKr=log(2)/T12Kr; %Hang so ban ra lBr=log(2)/T12Br; eq1='DNKr=-lmKr*NKr' %Pt phan huy eq2='DNBr=lmKr*NKr-lmBr*NBr'; eq3='DNSe=lmBr*NBr'; eqs=[eq1,',',eq2,',',eq3]; ints='NKr(0)=1,NBr(0)=0,NSe(0)=0'; %Dieu kien ban dau dsol=dsolve(eqs,ints); syms lmKr lmBr t Kr=subs(dsol.NKr,{lmKr,lmBr},{lKr,lBr}); Br=subs(dsol.NBr,{lmKr,lmBr},{lKr,lBr}); Se=subs(dsol.NSe,{lmKr,lmBr},{lKr,lBr}); ti=0:2:200; Kri=subs(Kr,t,ti); Bri=subs(Br,t,ti); Sei=subs(Se,t,ti); plot(ti,Kri,ti,Bri,ti,Sei); legend('Kr','Br','Se'); title('Qua trinh phan huy phong xa nguyen to Kr'); xlabel('Thoi gian/h'); ylabel('Khoi luong/mg') % End 0 20 40 60 80 100 120 140 160 180 200 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Thoi gian/h Khoi luong/mg Qua trinh phan huy phong xa nguyen to Kr Kr Br Se CÁC BÀI TOÁN CHUYỂN ĐỘNG 9 VD1: Qua bong nem xien 40 do o0o clc;clear;close all deq1='m*D2x=-k*Dx'; deq2='m*D2y=-g*m-k*Dy'; deqs=[deq1,',',deq2]; int1='x(0)=x0,Dx(0)=v0*cos(th)'; int2='y(0)=y0,Dy(0)=v0*sin(th)'; ints=[int1,',',int2]; dsol=dsolve(deqs,ints,'t'); x=dsol.x; y=dsol.y; syms t vx=diff(x,t); vy=diff(y,t); disp('x='); pretty(x); disp('y='); pretty(y); disp('Vx='); pretty(vx); disp('Vy='); pretty(vy); syms k m g x0 y0 v0 th %Bieu thuc khi k=0 xk0=limit(x,k,0); yk0=limit(y,k,0); vxk0=limit(vx,k,0); vyk0=limit(vy,k,0); disp('xk0=');pretty(xk0); disp('yk0=');pretty(yk0); disp('Vxk0=');pretty(vxk0); disp('Vyk0=');pretty(vyk0); gtri={0.1,.5,9.8,0,0,80,40*pi/180}; x1=subs(x,{k,m,g,x0,y0,v0,th},gtri); y1=subs(y,{k,m,g,x0,y0,v0,th},gtri); vx1=subs(vx,{k,m,g,x0,y0,v0,th},gtri); vy1=subs(vy,{k,m,g,x0,y0,v0,th},gtri); %Xac dinh thoi diem,vi tri cham dat tn0=11; f=inline(char(y1),'t'); tn=fsolve(f,tn0); xn=subs(x1,t,tn); disp('[tn,xn]=');disp([tn,xn]); % Bieu dien bang do hoa figure(1); subplot(2,2,1); ezplot(x1,[0 tn]); title('x1(t)'); grid on; subplot(2,2,2); ezplot(y1,[0 tn]); title('y1(t)'); grid on; subplot(2,2,3); ezplot(vx1,[0 tn]); title('Vx1(t)'); grid on; subplot(2,2,4); ezplot(vy1,[0 tn]); title('Vy1(t)'); grid on; figure(2); shg subplot(2,1,1); ezplot(x1,y1,[0 tn]); title('Quy dao y(x)'); grid on; pause; % % Hinh anh chuyen dong % ti=linspace(0,tn,200);p=.01; % xi=subs(x1,t,ti); % yi=subs(y1,t,ti); % subplot(2,1,2); % h=plot(xi(1),yi(1),':',xi(1),yi(1),'.','markersize',30,'erase','xor'); % xlabel('x'); ylabel('y'); % dx=.05*(max(xi)-min(xi)); % dy=.05*(max(yi)-min(yi)); % axis([min(xi)-dx, max(xi)+dx, min(yi), max(yi)+dy]); % xlabel('x'); ylabel('y'); % for k=1:length(ti); % set(h(1),'xdata',xi(1:k),'ydata',yi(1:k)); % set(h(2),'xdata',xi(k),'ydata',yi(k)); % pause(p) % end; End [tn,xn]= 8.2981 248.1338 10 . ni2=ncum2/ntrial; ti=[0 ti]; ni1=[N0 ni1]; ni2=[0 ni2]; ni1_gt=N0*exp(-p1*ti); ni2_gt=N0/(p1 -p2) *p1*exp( -p2* ti) -N0/(p1 -p2) *p1*exp(-p1*ti); plot(ti,ni1,ti,ni1_gt,ti,ni2,ti,ni2_gt); legend('n1i_{mphong}','n1i_{gtich}',. ni1=[N0 ni1];ni2=[N0 ni2]; ni1_gt=N0*exp(-p1*ti); %Cong thuc giai tich ni2_gt=N0/(p1 -p2) *p1*exp( -p2* ti)-N0/(p1 -p2) *p1*exp(-p1*ti); plot(ti,ni1,'r',ti,ni1_gt,'b',ti,ni2,'k',ti,ni2_gt,'g'); legend('n1i_{mo. so x2=subs(x,{w,t0,x0,v0,b},gtri2); v2=subs(v,{w,t0,x0,v0,b},gtri2); gtx2=subs(x2,t,t1); gtv2=subs(v2,t,t1); Ep2=gtw^2*gtx2.^2/2; Ek2=gtv2.^2/2; Et2=Ep2+Ek2; % Bieu dien do thi % - Ly do x(t), van toc v(t) figure(1); subplot(2,1,1);