Tài liệu Giải tích 2 - Code và command window bài tập lớn

Câu 1 đề 1

syms x y

a=input('nhap a: ');

b=input('nhap b: ');

z=(x^2)/(a^2)+(y^2)/(b^2);

t=linspace(-5,5);

[x,y]=meshgrid(t,t);

z=char(z);z=strrep(z,'*','.*');z=strrep(z,'^','.^');

z=eval(z);

set(surf(x,y,z),'FaceColor','g','FaceAlpha','0,3','EdgeColor','g');

rotate3d on;

docx 23 trang xuanthi 27/12/2022 3240
Bạn đang xem 20 trang mẫu của tài liệu "Tài liệu Giải tích 2 - Code và command window bài tập lớn", để tải tài liệu gốc về máy hãy click vào nút Download ở trên.

File đính kèm:

  • docxtai_lieu_giai_tich_2_code_va_command_window_bai_tap_lon.docx

Nội dung text: Tài liệu Giải tích 2 - Code và command window bài tập lớn

  1. zcd=[zcd;eval(f)] i=1+i; else disp('ham so khong co cuc tri ') a(i)=[];b(i)=[]; n=n-1; end else a(i)=[];b(i)=[]; n=n-1; end end syms e f c=e^2+f^2-32*log(e*f); a1=a(1);b1=b(1);c1=subs(c,[e f],[a1 b1]); a2=a(2);b2=b(2);c2=subs(c,[e f],[a2 b2]); a3=a(3);b3=b(3);c3=subs(c,[e f],[a3 b3]); a4=a(4);b4=b(4);c4=subs(c,[e f],[a4 b4]); x=linspace(-50,50,100); y=linspace(-50,50,100); [x,y]=meshgrid(x,y); f=x.^2+y.^2-32*log(x*y); set(surf(x,y,f),'facecolor','b','edgecolor','non','facealpha',.3); plot3(a1,b1,c1,'color','r','marker','o','MarkerSize', 20); plot3(a2,b2,c2,'color','r','marker','o','MarkerSize', 20); plot3(a3,b3,c3,'color','g','marker','o','MarkerSize', 20); plot3(a4,b4,c4,'color','g','marker','o','MarkerSize', 20); câu 4 đề 1 syms x y z tpz tpy I int(y,z) a=ans tpz=subs(a,z,1-y)-subs(a,z,0) b=int(tpz,y) tpy=subs(b,z,1)-subs(b,y,x^2) tpy=subs(b,y,1)-subs(b,y,x^2) I=int(tpy,x,-1,1) câu 5 đề 1 syms n s = symsum (n/3^n ,n ,1 ,inf) Câu 1 đề 2 syms x y z a=input('nhap a: '); b=input('nhap b: '); c=input('nhap c: '); [x y z]= ellipsoid(0,0,0,a,b,c); surf(x,y,z,'FaceColor','g','FaceAlpha','0,3','EdgeColor','r'); rotate3d on câu 2 đề 2
  2. a3=m(3);b3=n(3);c3=subs(c,[e f],[a3 b3]); a4=m(4);b4=n(4);c4=subs(c,[e f],[a4 b4]); phi=linspace (0,2*pi,100); r=linspace (0,1,100); [r phi]=meshgrid(r,phi); x=r.*cos(phi); y=r.*sin(phi); z=x.^2+2*y.^2; mesh(x,y,z,'FaceColor','b','FaceAlpha',0.5,'EdgeColor','non'); plot3(a1,b1,c1,'color','r','marker','o','MarkerSize', 20); plot3(a2,b2,c2,'color','r','marker','o','MarkerSize', 20); plot3(a3,b3,c3,'color','g','marker','o','MarkerSize', 20); plot3(a4,b4,c4,'color','g','marker','o','MarkerSize', 20); câu 4 đề 2 clc clear all xlabel('Truc Ox') ylabel('Truc Oy') grid on axis equal syms x y tp1 tp2 tp1=int(x*y+2*y,x) tp2=subs(tp1,x,y) tp1=subs(tp1,x,2-y) int(tp1-tp2,y,0,1) X=[0 1 2]; Y=[0 1 0]; line(X,Y); hold on fill(X,Y,'r') hold off câu 5 đề 2 syms n s = symsum ((-1)^n/n^2 ,n ,1 ,inf) câu 1 đề 3 clc clf hold on grid on xlabel('Truc Ox') ylabel('Truc Oy') zlabel('Truc Oz') rotate3d on title(' y=0, y=3, z=0, z=1-x^2')
  3. [m n]=loai(m,n); m=double(m);n=double(n);l=double(l); %chuyen sang dang double for i=1:length(m) A(i+k,2)=m(i); A(i+k,3)=n(i); A(i+k,1)=subs(f,[x y],[m(i) n(i)]); end %ve do thi [x,y]=meshgrid(x0-r:.1:x0+r,y0-r:.1:y0+r); z=[char(f) '+0.*x'];z=strrep(z,'^','.^');z=strrep(z,'*','.*'); z=eval(z); z(~isreal(z))=NaN; set(surf(x,y,z),'facecolor','b','edgecolor','non','facealpha',.3) hold on t=linspace(0,2*pi,50); x=r*cos(t)+x0; y=r*sin(t)+y0; z=[char(f) '+0.*x']; z=eval(f); if size(z,2)~=size(x,2) z=x; z(:,:)=double(f); end plot3(x,y,z,'r') if isempty(A) disp('khong co GTLN va GTNN') return end a=max(A(:,1)); b=min(A(:,1)); if a==b if a>subs(f,[x y],[x0+0.12 y0+0.12]) disp(['GTLN f(' num2str(A(1,2)) ',' num2str(A(1,3)) ')= ' num2str(A(1,1))]) else disp(['GTNN f(' num2str(A(1,2)) ',' num2str(A(1,3)) ')= ' num2str(A(1,1))]) end return end GTLN='GTLN la '; GTNN='GTNN la f('; for i=1:size(A) if A(i,1)==a GTLN=[GTLN 'f(' num2str(A(i,2)) ',' num2str(A(i,3)) ')= ']; text(A(i,2),A(i,3),a+1,['(' num2str(A(i,2)) ',' num2str(A(i,3)) ',' num2str(a) ')' ]) elseif A(i,1)==b GTNN=[GTNN 'f(' num2str(A(i,2)) ',' num2str(A(i,3)) ')= ']; text(A(i,2),A(i,3),b-1,['(' num2str(A(i,2)) ',' num2str(A(i,3)) ',' num2str(b) ')' ]) end end
  4. câu 3 đề 4 clc clf hold on grid on xlabel('Truc Ox') ylabel('Truc Oy') zlabel('Truc Oz') rotate3d on syms x y real f=x^3+y^3-3*x*y [a b]=solve([char(diff(f,'x')) '=0'],[char(diff(f,'y')) '=0']); % giai dao ham cap 1 a=double(a); b=double(b); % tinh dao ham cap 2 A=diff(f,2,x); B=diff(f,x);B=diff(B,y); C=diff(f,2,y); cd=zeros(0); ct=zeros(0); zcd=zeros(0); zct=zeros(0); n=size(a,1);i=1; while i 0 if sA > 0 % A > 0 la cuc tieu disp('cuc tieu la: ') ct=[ct;a(i) b(i)] disp(' gia tri cuc tieu tai : ') zct=[zct;eval(f)] i=i+1; elseif sA 0 la cuc dai disp('cuc dai la: ') cd=[cd;a(i) b(i)] disp(' gia tri cuc dai la: ') zcd=[zcd;eval(f)] i=1+i; else disp('ham so khong co cuc tri ') a(i)=[];b(i)=[]; n=n-1; end else a(i)=[];b(i)=[]; n=n-1; end end syms x y f= x^3+y^3-3*x*y; a1=a(1);b1=b(1);c1=subs(f,[x y],[a1 b1]); syms x y z= x^3+y^3-3*x*y; t=linspace(-2,2);
  5. for i=1:length(p) if (p(i)-x0)^2+(q(i)-y0)^2 lamda , m x , n y. [m n]=loai(m,n); m=double(m);n=double(n);l=double(l); %chuyen sang dang double for i=1:length(m) A(i+k,2)=m(i); A(i+k,3)=n(i); A(i+k,1)=subs(f,[x y],[m(i) n(i)]); end %ve do thi [x,y]=meshgrid(x0-r:.1:x0+r,y0-r:.1:y0+r); z=[char(f) '+0.*x'];z=strrep(z,'^','.^');z=strrep(z,'*','.*'); z=eval(z); z(~isreal(z))=NaN; set(surf(x,y,z),'facecolor','b','edgecolor','non','facealpha',.3) hold on t=linspace(0,2*pi,50); x=r*cos(t)+x0; y=r*sin(t)+y0; z=[char(f) '+0.*x']; z=eval(f); if size(z,2)~=size(x,2) z=x; z(:,:)=double(f); end plot3(x,y,z,'r') if isempty(A) disp('khong co GTLN va GTNN') return end a=max(A(:,1)); b=min(A(:,1)); if a==b if a>subs(f,[x y],[x0+0.12 y0+0.12]) disp(['GTLN f(' num2str(A(1,2)) ',' num2str(A(1,3)) ')= ' num2str(A(1,1))]) else
  6. x=2*sin(t).*cos(p); y=2*sin(t).*sin(p); z=2*cos(t); mesh(x,y,z,'FaceColor','c', 'FaceAlpha',0.5,'EdgeColor','non'); câu 5 đề 5 syms n s = symsum ((2^n - 5)/factorial(n) ,n ,1 ,inf) câu 1 đề 6 x=linspace(-10,10,100); z=linspace(-10,10,100); [x z]=meshgrid(x,z); y=z.^2-x.^2; mesh(x,y,z,'FaceColor','g','FaceAlpha',0.7,'EdgeColor','non') rotate3d on câu 2 đê 6 syms x y u; f=exp(u^2); subs(f,u,sin(x*y)); a=subs(f,u,sin(x*y)); fx=diff(a,x) fy=diff(a,y) câu 3 đề 6 clc clf hold on grid on xlabel('Truc Ox') ylabel('Truc Oy') zlabel('Truc Oz') rotate3d on syms x y lamda real f=2*x^2+12*x*y+y^2 phi=x^2 +4*y^2-25 L=f+lamda*(phi); Lx=diff(L,'x'); Ly=diff(L,'y'); [m n l]=solve(Lx,Ly,phi,'x','y','lamda');%giai he dao ham cap 1 voi: l lamda , m x , n y. m=double(m); m(abs(imag(m))>0.0000000001)=inf;m=m-imag(m)*1i; %loai so phuc n=double(n); n(abs(imag(n))>0.0000000001)=inf;n=n-imag(n)*1i; l=double(l); l(abs(imag(l))>0.0000000001)=inf;l=l-imag(l)*1i; Lxx=diff(Lx,'x');Lyy=diff(Ly,'y');Lxy=diff(Lx,'y'); %dao ham cap 2 phix=diff(phi,'x');phiy=diff(phi,'y'); %dao ham dieu kien for i=1:length(m) %xet cuc dai, cuc tieu if m(i)==inf || n(i)==inf || l(i)==inf continue end x=m(i); y=n(i);
  7. [r phi]=meshgrid(r,phi); x=r.*cos(phi)+1; y=r.*sin(phi); z=3-x-y; mesh(x,y,z,'FaceColor','y','EdgeColor','w','FaceAlpha',1); %Ve mat tru tron xoay phi=linspace(0,2*pi,500); t=linspace(0,4,500); [phi t]=meshgrid(phi,t); x=cos(phi)+1; y=sin(phi); z=t; for i=1:length(phi); for j=1:length(t); if x(i,j)+y(i,j)+z(i,j)>3 x(i,j)=NaN;y(i,j)=NaN;z(i,j)=NaN; end end end mesh(x,y,z,'FaceColor','c','FaceAlpha',0.5,'EdgeColor','non'); view(130,18); rotate3d on câu 5 đề 6 syms n s = symsum (1/(((3*n)+1)*(n-2)) ,n ,3 ,inf) câu 1 đề 7 syms x y a b f=x^2+sin(x*y); M=[1 0]; u=[a b]; fx=subs(diff(f,x),[x y ],M); fy=subs(diff(f,y),[x y ],M); f1=a*fx+b*fy-1; f2=a^2+b^2-1; nghiem=solve(f1,f2,[a b]); A=nghiem.a; B=nghiem.b; u1=[A(1) B(1)] u2=[A(2) B(2)] câu 2 đề 7 syms x y; f=1/(2*x +3*y); taylor(f,[x,y],[1,2],'order',2) câu 3 đề 7 clc clf
  8. set(surf(x,y,z),'FaceColor','g','FaceAlpha','0,3','EdgeColor','g'); plot3(a1,b1,c1,'color','r','marker','o','MarkerSize', 20); plot3(a2,b2,c2,'color','r','marker','o','MarkerSize', 20); cẫu 4 đề 7 clc clf hold on grid on xlabel('Truc Ox') ylabel('Truc Oy') zlabel('Truc Oz') rotate3d on syms x y z r t z=sqrt(x^2+y^2); a=diff(z,x); b=diff(z,y); x=r*cos(t); y=r*sin(t); z=eval(sqrt(x^2+y^2)); ds=eval(sqrt(1+a^2+b^2)); I=int(int(simplify((x+z)*sqrt(x^2+y^2)*ds),r,0,1),t,0,2*pi) %Ve mat cong S: %Vat the gioi han boi duong 0 2 z2(i,j)=NaN; end end end mesh(x,y,z2,'FaceColor','r','FaceAlpha',0.5,'EdgeColor','non')
  9. z=subs(diff(z,x),[x,y,z],[1,1,3])*(x-1)+subs(diff(z,y),[x,y,z],[1,1,3])*(y- 1)-3 câu 4 đề 8 syms x y z f=x*cos(y)+y*cos(z)+z*cos(x)-1 fx=diff(f,x) fz=diff(f,z) fy=diff(f,y) zx=-fx/fz zy=-fy/fz zxy=diff(zx,z)*zy+diff(zx,y) zn=solve(subs(f,[x y],[0 0])==0,z) subs(zxy,[x y z],[0 0 1]) câu 5 đề 8 syms n s = symsum ((3*(n^3)-4*(n^2)+5)/(4^n) ,n ,1 ,inf) câu 1 đề 9 z=linspace(0,4,100); x=linspace(-2,2,100); [x z]=meshgrid(x,z); y=x.^2 mesh(x,y,z,'FaceColor','y','FaceAlpha',0.7,'EdgeColor','g') rotate3d on câu 2 đề 9 syms x y u v; f=x*y*z-log(x+2*z-2) a=subs(f,[u,v],[x^2+y^2,x*y]); fx=diff(a,x) fy=diff(a,y) câu 3 đề 9 clc clf xlabel ('Ox') ylabel ('Oy') zlabel ('Oz') grid on hold on rotate3d on syms x y real f= (x+y^2)*exp(x/2) s=solve([diff(f,x)==0,diff(f,y)==0],[x,y]); a=double(s.x); b=double(s.y); c=subs(f,[x y],[a b]); [a b]=solve([char(diff(f,'x')) '=0'],[char(diff(f,'y')) '=0']); % giai dao ham cap 1 a=double(a); b=double(b);
  10. f=z-y^2; n=[diff(f,'x') diff(f,'y') diff(f,'z')]; n=n/sqrt(diff(f,'x')^2 + diff(f,'y')^2 + diff(f,'z')^2); %phuong phap tinh la phuong phap stokes p=(diff(R,'y')-diff(Q,'z'))*n(1,1); q=(diff(P,'z')-diff(R,'x'))*n(1,2); r=(diff(Q,'x')-diff(P,'y'))*n(1,3); z=y^2; f=(eval(p)+eval(q)+eval(r))*sqrt(1+diff(z,'x')^2+diff(z,'y')^2); % chuyen ve tich phan mat loai 2 syms r phi real x=r*cos(phi);y=r*sin(phi); % chuyen sang phuong phap truc toa do f=eval(f); I=int(int(f*r,'r',0,1),'phi',0,2*pi) %Vat the gioi han boi z=y^2,x^2+y^2=1,0=<z<=x^2+y^2 %Ve mat tru parapol z=y^2 phan nam trong mat tru tron xoay phi=linspace(0,2*pi,30); r=linspace(0,1,30); [r phi]=meshgrid(r,phi); x=r.*cos(phi); y=r.*sin(phi); z=y.^2; mesh(x,y,z,'FaceColor','b','EdgeColor','w','FaceAlpha',0.3); %Ve mat tru tron xoay phi=linspace(0,2*pi,30); t=linspace(0,1,30); [p t]=meshgrid(phi,t); x=cos(p); y=sin(p); z=t; mesh(x,y,z,'FaceColor','c','FaceAlpha',0.5,'EdgeColor','non'); %Ve duong giao tuyen t=linspace(0,2*pi,50); x=cos(t); y=sin(t); z=y.^2; plot3(x,y,z,'color','y','linewidth',3) hold off rotate3d on câu 5 đề 9 syms n s = symsum (n/(3^n) ,n ,1 ,inf) câu 1 đề 10 syms x y; u=(2*x+3*y)*log(x+2*y); diff(u,x,100);
  11. a4=m(4);b4=n(4);c4=subs(c,[e f],[a4 b4]); phi=linspace (0,2*pi,30); r=linspace (0,1,30); [r phi]=meshgrid(r,phi); x=r.*cos(phi); y=r.*sin(phi); z=x.^2+y.^2+x.*y; mesh(x,y,z,'FaceColor','b','FaceAlpha',0.5,'EdgeColor','non'); plot3(a1,b1,c1,'color','r','marker','o','MarkerSize', 20); plot3(a2,b2,c2,'color','r','marker','o','MarkerSize', 20); plot3(a3,b3,c3,'color','g','marker','o','MarkerSize', 20); plot3(a4,b4,c4,'color','g','marker','o','MarkerSize', 20); câu 4 đề 10 clc clf hold on grid on xlabel('Truc Ox') ylabel('Truc Oy') zlabel('Truc Oz') title('Duong cong C vang') syms x y z real P=3*x-y^2; Q=3*y-z^2; R=3*z-x^2; f=2*x+z-2; n=[diff(f,'x') diff(f,'y') diff(f,'z')]; n=n/sqrt(diff(f,'x')^2 + diff(f,'y')^2 + diff(f,'z')^2); %phuong phap tinh la phuong phap stokes p=(diff(R,'y')-diff(Q,'z'))*n(1,1); q=(diff(P,'z')-diff(R,'x'))*n(1,2); r=(diff(Q,'x')-diff(P,'y'))*n(1,3); z=2-2*x; f=(eval(p)+eval(q)+eval(r))*sqrt(1+diff(z,'x')^2+diff(z,'y')^2); % chuyen ve tich phan mat loai 2 syms r phi real x=r*cos(phi)-1;y=r*sin(phi); % chuyen sang phuong phap toa do cuc f=eval(f); I=int(int(f*r,'r',0,sqrt(3)),'phi',0,2*pi) %Vat the gioi han boi mat phang 2x+z=2 va mat paraboloid z=x^2+y^2 %Ve mat phang 2x+z=2 nam trong mat Paraboloid phi=linspace(0,2*pi,100); r=linspace(0,sqrt(3),100); [r phi]=meshgrid(r,phi); x=r.*cos(phi)-1; y=r.*sin(phi); z=2-2*x; surf(x,y,z,'EdgeColor','non','FaceColor','r','FaceAlpha',0.2);