GIẢI TÍCH NHÓM 1 function n1b1 % chuong trinh ve parabol elliptic a=input(''''nhap so a= ''''); b=input(''''nhap so b= ''''); [x,y]=meshgrid( 10 05 10); z=x ^2/a+y ^2/b; % lenh for o duoi de cat got do thi cho de[.]
GIẢI TÍCH: NHĨM 1: function n1b1 % chuong trinh ve parabol elliptic a=input('nhap so a= '); b=input('nhap so b= '); [x,y]=meshgrid(-10:.05:10); z=x.^2/a+y.^2/b; % lenh for o duoi de cat got thi cho dep mat :) for i=1:length(x) for j=1:length(x) if z(i,j)> 10^2/a || z(i,j) > 10^2/b z(i,j)=NaN;x(i,j)=NaN;y(i,j)=NaN; end end end set(surf(x,y,z),'facecolor','b','edgecolor','non','facealpha',.3); % ve thi rotate3d on end function n1b2 syms x y u=input('nhap ham u(x,y)= '); disp(['dao ham rieng theo x cap 10 tai (1,2) la: ' num2str(subs(diff(u,10,x) ,[x y],[1 2]))]) %lenh diff la dao ham % lenh subs la thay x va y bang so x0 va y0 end function n1b3 clc syms x y real f=input('nhap ham f(x,y)= '); [a b]=solve([char(diff(f,'x')) '=0'],[char(diff(f,'y')) '=0']); % giai dao ham cap a=double(a); b=double(b); % tinh dao ham cap 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 if sA > % A > la cuc tieu ct=[ct;a(i) b(i)]; zct=[zct;eval(f)]; i=i+1; elseif sA < % A > la cuc dai cd=[cd;a(i) b(i)]; zcd=[zcd;eval(f)]; i=1+i; else a(i)=[];b(i)=[]; n=n-1; end else a(i)=[];b(i)=[]; n=n-1; end end if size([zcd;zct],1)>= % ve hinh voi cuc tri tro len [x,y]=meshgrid(min(a)-abs(max( a )-min(a))/5:.1:max(a)+abs(max(a)-min(a))/5,min(b)abs(max(b)-min(b))/5:.1:max(b)+abs(max(b)-min(b))/5); f=char(f);f=strrep(f,'^','.^');f=strrep(f,'*','.*');f=eval(f); [x y f]=khu(x,y,f); set(surf(x,y,f),'facecolor','b','edgecolor','non','facealpha',.3) hold on ctri(cd,ct,zcd,zct) elseif size([zcd;zct],1)== % ve hinh voi cuc tri [x,y]=meshgrid(a-2:.1:a+2,b-2:.1:b+2); f=char(f);f=strrep(f,'^','.^');f=strrep(f,'*','.*');f=eval(f); [x y f]=khu(x,y,f); set(surf(x,y,f),'facecolor','b','edgecolor','non','facealpha',.3) hold on ctri(cd,ct,zcd,zct) else % khong co cuc tri disp('f khong co cuc tri chat, co cuc tri ko chat hay khong thi chiu :))' ) [x,y]=meshgrid(-2:.1:2); f=char(f);f=strrep(f,'^','.^');f=strrep(f,'*','.*');f=eval(f); [x y f]=khu(x,y,f); set(surf(x,y,f),'facecolor','b','edgecolor','non','facealpha',.3) end rotate3d on hold off xlabel('truc x') ylabel('truc y') zlabel('truc z') end function ctri(cd,ct,zcd,zct) % chuong trinh ve cuc tri cd=double(cd);zcd=double(zcd); for i=1:size(zcd,1) disp([' f co cuc dai chat: ' '(' num2str(cd(i,1)) ',' num2str(cd(i,2)) ',' num2str(zcd(i)) ')']) [x,y]=meshgrid(cd(i,1)-0.2:.05:cd(i,1)+0.2,cd(i,2)-0.2:.05:cd(i,2)+0.2); z=zcd(i)+x.*0+y.*0; set(surf(x,y,z),'facecolor','r','edgecolor','non') text(cd(i,1),cd(i,2),zcd(i)+.1,['cuc dai (' num2str(cd(i,1)) ',' num2str(cd(i,2)) ',' num2str(zcd(i)) ')']) end ct=double(ct);zct=double(zct); for i=1:size(zct,1) disp([' f co cuc tieu chat: ' '(' num2str(ct(i,1)) ',' num2str(ct(i,2)) ',' num2str(zct(i)) ')']) [x,y]=meshgrid(ct(i,1)-0.2:.05:ct(i,1)+0.2,ct(i,2)-0.2:.05:ct(i,2)+0.2); z=zct(i)+x.*0+y.*0; set(surf(x,y,z),'facecolor','r','edgecolor','non') text(ct(i,1),ct(i,2),zct(i)-.1,['cuc tieu (' num2str(ct(i,1)) ',' num2str(ct(i,2)) ',' num2str(zct(i)) ')']) end end function [x y f]=khu(x,y,f) % chuong trinh loai bo cac diem khong ton tai cua ham f for i=1:length(x) for j=1:length(y) if ~isreal(f(i,j)) f(i,j)=NaN;x(i,j)=NaN;y(i,j)=NaN; end end end end function n1b5 [x,y]=meshgrid(-sqrt(3):.05:sqrt(3)); % tao luoi z=sqrt(4-x.^2-y.^2); % mat tren z2=-sqrt(4-x.^2-y.^2)+2; % mat duoi for i=1:length(x) % vong lap loai bo cac diem nam ngoai mien giao for j=1:length(x) if x(i,j)^2+y(i,j)^2 > x(i,j)=NaN;y(i,j)=NaN; z(i,j)=NaN; z2(i,j)=NaN; end end end set(surf(x,y,z),'facecolor','b','edgecolor','non','facealpha',.3) %ve mat tren hold on set(surf(x,y,z2),'facecolor','b','edgecolor','non','facealpha',.3) % ve mat duoi pcolor(x,y,z2) % ve hinh chieu hold off rotate3d on syms x y phi r real z=sqrt(4-x^2-y^2); z2=-sqrt(4-x^2-y^2)+2; x=2*r*cos(phi);y=2*r*sin(phi); % dat x,y theo toa truc z=eval(z);z2=eval(z2); % cap nhat bien moi cho x va y V=int(int(4*r*(z-z2),'r',0,sqrt(3/4)),'phi',0,2*pi); %tinh tich phan kep V=double(V); disp(['the tich can tinh la: ' num2str(V)]) end function n1b6 syms x y real f=input('nhap ham f(x,y)= '); x=sqrt(1-y^2)+1; g=eval(f); %thay x vao f g=g*sqrt(1+diff(x,'y')^2); % tinh tich phan duong loai l=int(g,'y',-1,1); % tinh tich phan l=double(l); t=-pi/2:.1:pi/2; x=1+cos(t);y=sin(t); % dat x,y theo toa truc z=0+0*x; plot3(x,y,z) % ve duong disp(['tich phan I= ' num2str(l)]) end function n1b7 clc [x,y]=meshgrid(-1:.02:1); z=y.^2; for i=1:length(x) % loai cac diem bat dinh for j=1:length(x) if x(i,j)^2+y(i,j)^2 > % loai cac diem nam ngoai hinh tru x(i,j)=NaN; y(i,j)=NaN; z(i,j)=NaN; end end end set(surf(x,y,z),'facecolor','b','edgecolor','non','facealpha',.3) % ve mat giao tuyen hold on % ve duong giao tuyen t=linspace(0,2*pi,50); x=cos(t);y=sin(t);z=y.^2; plot3(x,y,z,'color','g') %tinh tich phan mat syms x y z real P=x+y; Q=2*x-z; R=y; 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); % tinh vector don vi cua vector phap %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); % da chuyen ve tich phan mat loai syms r phi real x=r*cos(phi);y=r*sin(phi); % chuyen sang phuong phap truc toa f=eval(f); S=int(int(f*r,'r',0,1),'phi',0,2*pi); %tinh tich phan S=double(S); disp(['Tich phan can tinh la: I= ' num2str(S)]) % ve vector phap tai M0 disp('nhap diem M0 thuoc mat z=y^2 va x^2+y^2 = x^2+y^2 ') disp('vidu M(0,-1,2), thi ta nhap: 0,-1,2') m=input('M0= ','s'); m=str2num(m); x=m(1,1);y=m(1,2);z=m(1,3); n=eval(n);% the toa diem vao vector title(['mat z=y^2 nam hinh tru x^2+y^2=1 ' 'Va phap vector tai diem M0(' num2str(x) ',' num2str(y) ',' num2str(z) ')']) % tao tieu de %bat dau ve vector phap t=linspace(0,1,20); x=n(1,1)*t+x; y=n(1,2)*t+y; z=n(1,3)*t+z; plot3(x,y,z,'color','r') hold off rotate3d on % OK men :)) end NHÓM 3: function n3b1 disp('nhap a b thuoc z=x^2/a^2-y^2/b^2') a=input('nhap a= '); b=input('nhap b= '); c=[abs(a) abs(b)]; c=max(c); [x,y]=meshgrid(-c:.1:c); z=x.^2/a.^2-y.^2/b.^2; set(surf(x,y,z),'facecolor','b','edgecolor','non','facealpha',.3) end function n3b2 syms x y u real f=input('nhap ham f(u)= '); u=input('nhap ham u(x,y)= '); disp('phap lan luoc cac toa cua M0:') x0=input('x0= '); y0=input('y0= '); f=eval(f); %thay u(x,y) vao f(u) c=subs(f,[x y],[x0 y0]); %tinh f tai M0 c=double(c); %tinh dao ham x=x0;y=y0; fx=diff(f,'x');a=eval(fx); fy=diff(f,'y');b=eval(fy); %xuat f'x va f'y disp(['f`x= ' num2str(a)]) disp(['f`y= ' num2str(b)]) %ve thi [x,y]=meshgrid(x0-2:.1:x0+2,y0-2:.1:y0+2); f=char(f);f=strrep(f,'^','.^');f=strrep(f,'*','.*'); f=eval(f); [x y f]=khu(x,y,f); set(surf(x,y,f),'facecolor','b','edgecolor','non','facealpha',.3) hold on t=linspace(-2,2,40); x=x0+t; y=y0+0*t; z=c+a*t; plot3(x,y,z,'r','linewidth',2) x=x0+0*t; y=y0+t; z=c+b*t; plot3(x,y,z,'r','linewidth',2) text(x0,y0,c+.2,['M0 (' num2str(x0) ',' num2str(y0) ',' num2str(a) ')']) hold off rotate3d on end function [x y f]=khu(x,y,f) % chuong trinh loai bo cac diem khong ton tai cua ham f f=double(f); for i=1:length(x) for j=1:length(y) if ~isreal(f(i,j)) f(i,j)=NaN;x(i,j)=NaN;y(i,j)=NaN; end end end end function n3b3 warning off syms x y lamda real f=input('nhap ham f(x,y)= '); disp('nhap parabol y(x) vd: y=6+4*x^2 ') phi=input('y = '); hold on L=f+lamda*(phi-y); Lx=diff(L,'x'); Ly=diff(L,'y'); [l m n]=solve(Lx,Ly,phi-y,'x','y','lamda'); %giai he dao ham cap 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 phix=diff(phi-y,'x');phiy=diff(phi-y,'y'); %dao ham dieu kien k=0; 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);lamda=l(i); dphi=-eval(phix)/eval(phiy); A=eval(Lxx);B=eval(Lxy);C=eval(Lyy); dL=A+B*dphi+C*dphi^2; z=eval(f); if (dL > && isreal(m(i))) || ((dphi==inf || dphi==-inf) && C>0) %dao ham cap > => cuc tieu k=k+1; disp([' diem (' num2str(m(i)) ',' num2str(n(i)) ',' num2str(z) ') la diem cuc tieu']) text(x,y,z-1,['cuc tieu (' num2str(m(i)) ',' num2str(n(i)) ',' num2str(z) ')' ]) elseif (dL < && isreal(m(i))) || ((dphi==inf || dphi==-inf) && C cuc dai k=k+1; disp([' diem (' num2str(m(i)) ',' num2str(n(i)) ',' num2str(z) ') la diem cuc dai']) text(x,y,z+1,['cuc dai (' num2str(m(i)) ',' num2str(n(i)) ',' num2str(z) ')' ]) end end %ve thi if k~=0 x=linspace(min(m)-2,max(m)+2,20); y=eval(phi); [x,y]=meshgrid(x,y); z=char(f);z=strrep(z,'*','.*');z=strrep(z,'^','.^'); z=eval(f); [x y z]=khu(x,y,z);