1. Trang chủ
  2. » Khoa Học Tự Nhiên

các bai tập mẫu matlab,lập trình c cho đại học,cao học và nghiên cứu sinh

16 472 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 16
Dung lượng 69,5 KB

Nội dung

các đề thi matlablập trình c cho học viên cao hocnghiên cứu sinh de 1 clear all;clc; %1 eq=DN1=a1N1, DN2=a1N1a2N2, DN3=a2N2; % he pt vi phan % A1: so khoi cua nguyen to 1; AV=6.022e+26; => N1(0)= AVA1; dk=N1(0)=AVA1, N2(0)=0, N3(0)=0; % dieu kien ban dau N1 N2 N3 = dsolve(eq,dk) %2 % A1=A2=A3=76 => M1 M2 M3= (A1AV)N1 N2 N3; T1=14.8;T2=16.1; syms A1 AV M1=N1A1AV; M2=simple(N2A1AV); M3=simple(N3A1AV); a1=log(2)T1;a2=log(2)T2; M1=subs(M1,a1,a1), M2=subs(M2,{a1,a2},{a1,a2}), M3=subs(M3,{a1,a2},{a1,a2}) ezplot(M1,0 200);hold on; h2=ezplot(M2,0 200); set(h2,Color,red) h3=ezplot(M3,0 200); set(h3,Color,g) legend(Kr,Br,Se); title(do thi khoi luong theo thoi gian); xlabel(Time(h));ylabel(Mass(kg));grid on de 2 clear all; clc; % y=(1+x2)2+2xy(1+x2) ;y(0)=10 dy=inline(((1+x2)2+2xy(1))(1+x2),x,y) x y=ode45(dy,0:0.1:15,10); %2,3 figure(1);title(do thi ham so);hold on; grid on; xlabel(chon Diem 0 roi nhan nut Enter,Color,red); xn,fn=sp_solve(x,y); % can file: sp_solve.m plot(xn,fn,ro); xlabel(chon Diem Cuc Tieu roi nhan nut Enter,Color,k); xm,fm=sp_min(x,y); % can file: sp_min.m plot(xm,fm,r); xlabel( ); de 3 clear all;clc; dy=DT=r(TTe); T=dsolve(dy,T(0)=T0) T=subs(T,{T0,Te,r},{85,23,0.025}) ezplot(T,0 200); grid on; xlabel(Time(s));ylabel(T(Celsius)); hold on; plot(0 200,23 23,r); %2 dy=DT=r1(TTe)r2(TTe)2; T2=dsolve(dy,T(0)=T0) T2=subs(T2,{T0,Te,r1,r2},{85,23,0.025,0.001}); T2=simple(T2) figure(2); ezplot(T2,0 200);hold on;grid on; xlabel(Time(s));ylabel(T(Celsius)); de 4 clear all;clc; %y=y(1); y=y(2);y=y(2) %he pt vi phan: y(1)=y(2);y(2)=y(2)+6y(1)2; dy=inline(y(2);y(2)+6y(1)2,x,y) %y(0)=1;y(1)=2; dy0=6:0.1:0; for k=1:length(dy0) x y=ode45(dy,0:.01:1,1;dy0(k)); yend(k)=y(end,1); end dyn,yn=sp_solve(dy0,yend2) x y=ode45(dy,0:.01:1,1;dyn); plot(x,y(:,1),r);hold on;grid on; % ve: y=f(x) plot(x,y(:,2),b); %ve: y=g(x) legend(y=f(x),dydx=g(x)); title(dk: y(0)=1;y(1)=2); %2 % y(0)=1; y(1)=1; figure(2); y0=2:0.1:0; for k=1:length(y0) x y=ode45(dy,0:.01:1,y0(k);1); dyend(k)=y(end,2); end yn,dyn=sp_solve(y0,dyend1) x y=ode45(dy,0:.01:1,yn;1); plot(x,y(:,1),r);hold on;grid on; % ve: y=f(x) plot(x,y(:,2),b); %ve: y=g(x) legend(y=f(x),dydx=g(x)); title(dk: dy(0)=1;dy(1)=1) de5 clear all;clc; % x=(km)x (muy)x; k=10;m=0.1;mu=0.01;x0=0;v0=0.1 dx=D2x=(km)x muDx; x=dsolve(dx,x(0)=x0,Dx(0)=v0) 2 x2=subs(x,{k,m,mu,x0,v0},{k,m,mu,x0,v0}); x2=simple(x2) v=diff(x2); t=0:0.01:6; x2=subs(x2,t); v=subs(v,t); title(toa do,van toc theo thoi gian);hold on; grid on; plot(t,x2,r); plot(t,v); legend(toa do,van toc); figure(2);title(khong gian pha) ;hold on; grid on; plot(x2,v); figure(3); title(nang luong);hold on; grid on; Ed=mv.22; Et=k(x2).22; E=Ed+Et; plot(t,Ed); plot(t,Et,g); plot(t,E,r); legend(dong nang,the nang,co nang); sp_min function xn,fxn=sp_min(xi,yi,lim); if nargin z = 1y = a0x+a1 xi=0 0.2 0.4 0.6 0.9 1.2 1.4 1.8 2 yi=0.97 0.69 0.57 0.456 0.36 0.31 0.265 0.2 0.196; a=polyfit(xi,yi.1,1); a0=a(1), a1=a(2) %b) plot(xi,yi,ro); hold on; grid on; x=0:0.01:2; z=polyval(a,x); plot(x,z.1); ĐỀ 13 clear all;clc; xi=0 13 24 36 40 51 63 74 82 85; yi=0 15 34 49 27 11 19 61 37 0; sp=spline(xi,yi); x=0:0.5:85; y=ppval(sp,x); plot(x,y);hold on;grid on; %b) sp2=spline(xi,yi); xlabel(chon Diem xa bo nhat roi Enter,Color,r); xm ym=ginput(1); f=inline(ppval(sp,x),x,sp) xm ym= fminsearch(f,xm,,sp2); plot(xm,ym,r); diem_xa_bo_nhat=xm ym %c) I=0; for i=1:length(x)1 r=x(i+1)x(i), y(i+1)y(i); I=I+norm(r); end quang_duong=I Đề 14 clear all;clc; ti=0:2:46; Ti=68.8 64.8 62.1 59.9 57.7 55.9 45.9 44.8 43.7 42.6 41.7 40.8,... 53.9 52.3 50.8 49.5 48.1 46.8 39.9 39.3 38.6 37.7 37.0 36.4; T=dsolve(DT=r(T17),T(0)=68.8); Tend=subs(T,t,ti(end)); % nhiet do cuoi:tai t=46s r=solve(TendTi(end),r); % tinh so bo he so r r=subs(r); r=linspace(r2,r2,50); %phuong phap ban: for k=1:length(r) Tk=subs(T,r,r(k)); Ss=subs(Tk,ti)Ti ; % Vector gia tri sai so nhiet do tai cac thoi gian ti Bp(k)=dot(Ss,Ss); % tong binh phuong sai so nhiet do end %phuong phap sai so binh phuong cuc tieu: xlabel(chon Diem Cuc Tieu roi Enter,Color,r);hold on; rr bp=sp_min(r,Bp); r=rr, %gia tri r de tong binh phuong sai so cuc tieu %b) T=subs(T,r,r) pl_min function xn,fn=pl_min(xi,yi); p=polyfit(xi,yi,length(xi)1); f=inline(polyval(p,x),x,p); x=linspace(xi(1),xi(end),100); y=f(x,p); xlabel(chon Cac cuc tieu roi Enter,Color,k);hold on;grid on; plot(x,y,b); x0,y0=ginput; for k=1:length(x0); xn(k),fn(k)=fminsearch(f,x0(k),,p); end; pl_solve function xn,fn=pl_solve(xi,yi); p=polyfit(xi,yi,length(xi)1); f=inline(polyval(p,x),x,p); x=linspace(xi(1),xi(end),100); y=f(x,p); xlabel(chon Cac diem 0 roi Enter,Color,r);hold on;grid on; plot(x,y,r); x0,y0=ginput; for k=1:length(x0); xn(k),fn(k)=fsolve(f,x0(k),,p); end; đề 6_1 clear all;clc % x= y(1); y=y(2); z=y(3) dy=inline(10(y(2)y(1));126.52y(1)y(2)y(1)y(3);y(1)y(2)8y(3)3,t,y); t y=ode45(dy,0 8,7.69 ;15.61;90.39); plot(t,y(:,1),r); hold on;grid on plot(t,y(:,2),g);plot(t,y(:,3)); legend(x(t),y(t),z(t)); %b) % y=y(1); y=y(2); y=(y+8x3y3))x; dy=inline(y(2); (y(2)+8x3y(1)3)x,x,y); x y=ode45(dy,1 4,12;12); figure(2); plot(x,y(:,1),r); hold on; grid on; plot(x,y(:,2),g); legend(y(x),dydx); Đề 7_1 clear all;clc; % bai nay giong De 2 dy=inline((1+x2)+ 2xy(1+x2),x,y); x,y=ode45(dy,0 15,10); %2 xlabel(Chon diem 0 roi Enter,Color,r); hold on;grid on; x0 y0=sp_solve(x,y); plot(x0,y0,ro); %3 xlabel(Chon cuc tieu roi Enter,Color,k); xm ym=sp_min(x,y); plot(xm,ym,r); xlabel( ); Đề 8_1 clear all;clc; % bai nay giong De 2 % y(0)=0.3; y(0)=0; dy=inline(y(2);0.2y(2)10sin(y(1)),x,y); x,y=ode45(dy,0 10,0.3;0); %2 xlabel(Chon tat ca Cac diem 0 roi Enter,Color,r); hold on;grid on; plot(x,y(:,1));plot(x,y(:,2),g);legend(y(x),dydx); x0 y0=sp_solve(x,y(:,1)); plot(x0,y0,ro); %3 xlabel(Chon Cac cuc tieu roi Enter,Color,k); xm ym=sp_min(x,y(:,1)); plot(xm,ym,r); xlabel( ); Đề 9_1 clear all;clc xi=0:8; yi=.6 .75 .8 .5 .1 .5 .7 .3 .1; a=polyfit(xi,yi,8); sp=spline(xi,yi); x=0:0.05:8; y=polyval(a,x); plot(x,y,r); hold on; grid on; ys=ppval(sp,x); plot(x,ys,y); legend(da thuc,spline); plot(xi,yi,k+); %2 figure(2); xn yn=pl_solve(xi,yi); xm ym=pl_min(xi,yi); figure(3); xlabel(chon Cac diem 0 roi Enter,Color,r);hold on; xn2 yn2=sp_solve(xi,yi); xlabel(chon Cac diem cuc tieu roi Enter,Color,k); xm2 ym2=sp_min(xi,yi); figure(1); plot(xn xn2,yn yn2,ro); plot(xm xm2,ym ym2,r); Đề 10_1 clear all;clc; % y=aexp(bx2+cx) =>ln(y)=ln(a)+bx2+cx; xi=0:0.2:1; yi=2.3 2.87 3.72 5.02 7.05 10.3; p=polyfit(xi,log(yi),2); a=exp(p(3)), b=p(1), c=p(2) %b) plot(xi,yi,ro); hold on; grid on; x=0:0.01:1; z=polyval(p,x); y=exp(z); plot(x,y); Đề 11_1 clear all;clc la=0.589 0.55 0.486 0.443 0.402; n=1.628 1.64 1.652 1.668 1.679; LA=la.2; % LA= 1la2; a=polyfit(LA,n,2); A=a(3),B=a(2),C=a(1) %2 lai=0.4:0.01:0.75; ni=polyval(a,lai.2); plot(la,n,r);hold on;grid on plot(lai,ni); xlabel(lambda(106m));ylabel(n); %3 lado=0.72; n_do=polyval(a,lado2) Đề 12_1 clear all;clc % y=1(a0x+a1) => z = 1y = a0x+a1 xi=0 0.2 0.4 0.6 0.9 1.2 1.4 1.8 2 yi=0.97 0.69 0.57 0.456 0.36 0.31 0.265 0.2 0.196; a=polyfit(xi,yi.1,1); a0=a(1), a1=a(2) %b) plot(xi,yi,ro); hold on; grid on; x=0:0.01:2; z=polyval(a,x); plot(x,z.1);

các đề thi matlab-lập trình c cho học viên cao hocnghiên cứu sinh de clear all;clc; % -1 eq='DN1=-a1*N1, DN2=a1*N1-a2*N2, DN3=a2*N2'; % he pt vi phan % A1: so khoi cua nguyen to 1; AV=6.022e+26; => N1(0)= AV/A1; dk='N1(0)=AV/A1, N2(0)=0, N3(0)=0'; % dieu kien ban dau [N1 N2 N3] = dsolve(eq,dk) % -2 % A1=A2=A3=76 => [M1 M2 M3]= (A1/AV)*[N1 N2 N3]; T1=14.8;T2=16.1; syms A1 AV M1=N1*A1/AV; M2=simple(N2*A1/AV); M3=simple(N3*A1/AV); a1=log(2)/T1;a2=log(2)/T2; M1=subs(M1,'a1',a1), M2=subs(M2,{'a1','a2'},{a1,a2}), M3=subs(M3,{'a1','a2'},{a1,a2}) ezplot(M1,[0 200]);hold on; h2=ezplot(M2,[0 200]); set(h2,'Color','red') h3=ezplot(M3,[0 200]); set(h3,'Color','g') legend('Kr','Br','Se'); title('do thi khoi luong theo thoi gian'); xlabel('Time(h)');ylabel('Mass(kg)');grid on de clear all; clc; % y'=[(1+x^2)^2+2xy]/(1+x^2) ;y(0)=-10 dy=inline('((1+x^2)^2+2*x*y(1))/(1+x^2)','x','y') [x y]=ode45(dy,[0:0.1:15],-10); % -2,3 figure(1);title('do thi ham so');hold on; grid on; xlabel('chon Diem roi nhan nut Enter','Color','red'); [xn,fn]=sp_solve(x,y); % can file: sp_solve.m plot(xn,fn,'ro'); xlabel('chon Diem Cuc Tieu roi nhan nut Enter','Color','k'); [xm,fm]=sp_min(x,y); % can file: sp_min.m plot(xm,fm,'r*'); xlabel(' '); de clear all;clc; dy='DT=-r*(T-Te)'; T=dsolve(dy,'T(0)=T0') T=subs(T,{'T0','Te','r'},{85,23,0.025}) ezplot(T,[0 200]); grid on; xlabel('Time(s)');ylabel('T(Celsius)'); hold on; plot([0 200],[23 23],'r-'); % dy='DT=-r1*(T-Te)-r2*(T-Te)^2'; T2=dsolve(dy,'T(0)=T0') T2=subs(T2,{'T0','Te','r1','r2'},{85,23,0.025,0.001}); T2=simple(T2) figure(2); ezplot(T2,[0 200]);hold on;grid on; xlabel('Time(s)');ylabel('T(Celsius)'); de clear all;clc; %y=y(1); y'=y(2);y"=y(2)' %he pt vi phan: y(1)'=y(2);y(2)'=-y(2)+6*y(1)^2; dy=inline('[y(2);-y(2)+6*y(1)^2]','x','y') %y(0)=1;y(1)=2; dy0=-6:0.1:0; for k=1:length(dy0) [x y]=ode45(dy,[0:.01:1],[1;dy0(k)]); yend(k)=y(end,1); end [dyn,yn]=sp_solve(dy0,yend-2) [x y]=ode45(dy,[0:.01:1],[1;dyn]); plot(x,y(:,1),'r');hold on;grid on; % ve: y=f(x) plot(x,y(:,2),'b'); %ve: y'=g(x) legend('y=f(x)','dy/dx=g(x)'); title('dk: y(0)=1;y(1)=2'); % -2 % y'(0)=-1; y'(1)=1; figure(2); y0=-2:0.1:0; for k=1:length(y0) [x y]=ode45(dy,[0:.01:1],[y0(k);-1]); dyend(k)=y(end,2); end [yn,dyn]=sp_solve(y0,dyend-1) [x y]=ode45(dy,[0:.01:1],[yn;-1]); plot(x,y(:,1),'r');hold on;grid on; % ve: y=f(x) plot(x,y(:,2),'b'); %ve: y'=g(x) legend('y=f(x)','dy/dx=g(x)'); title('dk: dy(0)=-1;dy(1)=1') de5 clear all;clc; % x''=-(k/m)*x - (muy)*x'; k=10;m=0.1;mu=0.01;x0=0;v0=0.1 dx='D2x=-(k/m)*x -mu*Dx'; x=dsolve(dx,'x(0)=x0','Dx(0)=v0') x2=subs(x,{'k','m','mu','x0','v0'},{k,m,mu,x0,v0}); x2=simple(x2) v=diff(x2); t=0:0.01:6; x2=subs(x2,t); v=subs(v,t); title('toa do,van toc theo thoi gian');hold on; grid on; plot(t,x2,'r'); plot(t,v); legend('toa do','van toc'); figure(2);title('khong gian pha') ;hold on; grid on; plot(x2,v); figure(3); title('nang luong');hold on; grid on; Ed=m*v.^2/2; Et=k*(x2).^2/2; E=Ed+Et; plot(t,Ed); plot(t,Et,'g'); plot(t,E,'r'); legend('dong nang','the nang','co nang'); sp_min function [xn,fxn]=sp_min(xi,yi,lim); if nargin[...]... thuc','spline'); plot(xi,yi,'k+'); % -2 figure(2); [xn yn]=pl_solve(xi,yi); [xm ym]=pl_min(xi,yi); figure(3); xlabel('chon Cac diem 0 roi Enter','Color','r');hold on; [xn2 yn2]=sp_solve(xi,yi); xlabel('chon Cac diem cuc tieu roi Enter','Color','k'); [xm2 ym2]=sp_min(xi,yi); figure(1); plot([xn xn2],[yn yn2],'ro'); plot([xm xm2],[ym ym2],'r*'); Đề 10_1 clear all;clc; % y=a*exp(b*x^2 +c* x)... [x,y]=ode45(dy,[0 10],[0.3;0]); % -2 xlabel('Chon tat ca Cac diem 0 roi Enter','Color','r'); hold on;grid on; plot(x,y(:,1));plot(x,y(:,2),'g');legend('y(x)','dy/dx'); [x0 y0]=sp_solve(x,y(:,1)); plot(x0,y0,'ro'); % -3 xlabel('Chon Cac cuc tieu roi Enter','Color','k'); [xm ym]=sp_min(x,y(:,1)); plot(xm,ym,'r*'); xlabel(' '); Đề 9_1 clear all;clc xi=0:8; yi=[.6 75 8 5 1 -.5 -.7 -.3 1]; a=polyfit(xi,yi,8);... legend('y(x)','dy/dx'); Đề 7_1 clear all;clc; % bai nay giong De 2 dy=inline('(1+x^2)+ 2*x*y/(1+x^2)','x','y'); [x,y]=ode45(dy,[0 15],-10); % -2 xlabel('Chon diem 0 roi Enter','Color','r'); hold on;grid on; [x0 y0]=sp_solve(x,y); plot(x0,y0,'ro'); % -3 xlabel('Chon cuc tieu roi Enter','Color','k'); [xm ym]=sp_min(x,y); plot(xm,ym,'r*'); xlabel(' '); Đề 8_1 clear all;clc; % bai nay giong De 2 %... r=subs(r); r=linspace(r/2,r*2,50); %phuong phap ban: for k=1:length(r) Tk=subs(T,'r',r(k)); Ss=subs(Tk,ti)-Ti ; % Vector gia tri sai so nhiet do tai cac thoi gian ti Bp(k)=dot(Ss,Ss); % tong binh phuong sai so nhiet do end %phuong phap sai so binh phuong cuc tieu: xlabel('chon Diem Cuc Tieu roi Enter','Color','r');hold on; [rr bp]=sp_min(r,Bp); r=rr, %gia tri r de tong binh phuong sai so cuc tieu % ... b) T=subs(T,'r',r) pl_min function [xn,fn]=pl_min(xi,yi); p=polyfit(xi,yi,length(xi)-1); f=inline('polyval(p,x)','x','p'); x=linspace(xi(1),xi(end),100); y=f(x,p); xlabel('chon Cac cuc tieu roi Enter','Color','k');hold on;grid on; plot(x,y,'b'); [x0,y0]=ginput; for k=1:length(x0); [xn(k),fn(k)]=fminsearch(f,x0(k),[],p); end; pl_solve function [xn,fn]=pl_solve(xi,yi); p=polyfit(xi,yi,length(xi)-1);... [xn,fn]=pl_solve(xi,yi); p=polyfit(xi,yi,length(xi)-1); f=inline('polyval(p,x)','x','p'); x=linspace(xi(1),xi(end),100); y=f(x,p); xlabel('chon Cac diem 0 roi Enter','Color','r');hold on;grid on; plot(x,y,'r'); [x0,y0]=ginput; for k=1:length(x0); [xn(k),fn(k)]=fsolve(f,x0(k),[],p); end; đề 6_1 clear all;clc % x= y(1); y=y(2); z=y(3) dy=inline('[10*(y(2)-y(1));126.52*y(1)-y(2)-y(1)*y(3);y(1)*y(2)-8*y(3)/3]','t','y');... y=a*exp(b*x^2 +c* x) =>ln(y)=ln(a)+b*x^2 +c* x; xi=0:0.2:1; yi=[2.3 2.87 3.72 5.02 7.05 10.3]; p=polyfit(xi,log(yi),2); a=exp(p(3)), b=p(1), c= p(2) % b) plot(xi,yi,'ro'); hold on; grid on; x=0:0.01:1; z=polyval(p,x); y=exp(z); plot(x,y); Đề 11_1 clear all;clc la=[0.589 0.55 0.486 0.443 0.402]; n=[1.628 1.64 1.652 1.668 1.679]; LA=la.^-2; % LA= 1/la^2; a=polyfit(LA,n,2); A=a(3),B=a(2) ,C= a(1) % -2 lai=0.4:0.01:0.75;... -3 lado=0.72; n_do=polyval(a,lado^-2) Đề 12_1 clear all;clc % y=1/(a0*x+a1) => z = 1/y = a0*x+a1 xi=[0 0.2 0.4 0.6 0.9 1.2 1.4 1.8 2] yi=[0.97 0.69 0.57 0.456 0.36 0.31 0.265 0.2 0.196]; a=polyfit(xi,yi.^-1,1); a0=a(1), a1=a(2) % b) plot(xi,yi,'ro'); hold on; grid on; x=0:0.01:2; z=polyval(a,x); plot(x,z.^-1); Đề 13_1 clear all;clc; xi=[0 13 24 36 40 51 63 74 82 85]; yi=[0 15 34 49... sp=spline(xi,yi); x=0:0.5:85; y=ppval(sp,x); plot(x,y);hold on;grid on; % -b) sp2=spline(xi,-yi); xlabel('chon Diem xa bo nhat roi Enter','Color','r'); [xm ym]=ginput(1); f=inline('ppval(sp,x)','x','sp') [xm ym]= fminsearch(f,xm,[],sp2); plot(xm,-ym,'r*'); diem_xa_bo_nhat=[xm -ym] % -c) I=0; for i=1:length(x)-1 r=[x(i+1)-x(i), y(i+1)-y(i)]; I=I+norm(r); end quang_duong=I ...figure(1);title('do thi ham so');hold on; grid on; xlabel('chon Diem roi nhan nut Enter','Color','red'); [xn,fn]=sp_solve(x,y);... fnplt(sp,lim);grid on; [x0,y0]=ginput; for k=1:length(x0); [xn(k),fxn(k)]=fsolve(f,x0(k),[],sp); end; Đề 4b clear all;clc; %y=y(1); y'=y(2);y"=y(2)' %he pt vi phan: y(1)'=y(2);y(2)'=-y(2)+6*y(1)^2;... y=f(x) plot(x,y(:,2),'b'); %ve: y'=g(x) legend('y=f(x)','dy/dx=g(x)'); title('dk: dy(0)=-1;dy(1)=1') ĐỀ clear all;clc % x= y(1); y=y(2); z=y(3) dy=inline('[10*(y(2)-y(1));126.52*y(1)-y(2)-y(1)*y(3);y(1)*y(2)-8*y(3)/3]','t','y');

Ngày đăng: 27/11/2015, 10:34

TỪ KHÓA LIÊN QUAN

w