1. Trang chủ
  2. » Giáo án - Bài giảng

Tổng hợp các core bài tập matlap

37 517 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 37
Dung lượng 300,5 KB

Nội dung

Tổng hợp các core bài tập matlap

Cao V¨n ChÝnh_B1K52 Tổng hợp code các bài thực hành Matlab Bai 1 clc x=-2:0.01:2 y=exp(-0.3.*x.^2- 0.5.*x +1).*cos(20.*x) subplot(2,1,1)% lenh subplot nay chia man %hinh do thi theo 2 hang 1 cot vi tri 1 plot(x,y,'m')%lenh nay ve do thi vao phan %hinh minh chia ra vào subplot 1 %hinhcon 2 subplot(2,1,2) % ve dang ham nay thi khai bao truc tiep ham trong dau '' fplot('exp(-0.3.*x.^2- 0.5.*x+1).*cos(20.*x)',[-2 2]) title('do thi ham so ')% lenh nay dien %tieu de cho do thi xlabel('truc x')% ghi tieu de cho truc x xlabel('truc y')% ghi tieu de cho truc y Bai 2 %hinh con 1 x=0:0.05:4;y=3.*sin(pi.*x);y1=exp(-0.2.*x) subplot(2,1,1);plot(x,y,'r',x,y1,'b') gtext('giao diem 1')% gan chu thich vao %cac giao diem giua 2 do thi gtext('giao diem 2') gtext('giao diem 3') gtext('giao diem 4') % hinh con 2& 3 x1=0:0.05:10;y2=exp(-0.2.*x1).*cos(x1) subplot(2,2,3);bar(x1,y2)% ve do thi dang cot subplot(2,2,4);stairs(x1,y2)%ve do thi dang bac thang Bai 3 % Chu y ham function o day chi chay dc tren Window thui,voi may tinh tren truong thi khong chay duoc dau!!! %cau a function tong=bai3a(n,x) s=0; for k=1:n s=s+((-1).^k./k).*((-(x-1).^k).*(x>0 & x<1)+((1./x-1).^k).*(x>=1)); end tong=s % bai3b function tong=bai3b(x) ak=1; ss=1e-6; s1=0; k=0; while any(abs(ak)>ss) k=k+1 ak=((-1).^k./k).*((-(x-1).^k).*(x>0 & x<1)+((1./x-1).^k).*(x>=1)); s1=s1+ak; end tong=s1 %bai 3c x=0.1:0.1:10; plot(x,bai3a(1,x),'r');hold on; plot(x,bai3a(5,x),'c');hold on; plot(x,bai3a(10,x),'b');hold on; plot(x,bai3b(x),'m');hold on; legend('s1','s5','s10','s') gtext('s1') ;gtext('s5') 1 Cao V¨n ChÝnh_B1K52 gtext('s10') ;gtext('s') Bai 4 [x,y]=meshgrid(-2:.1:2); z=2.*x.*y./(x.^2 +y.^2 +1); subplot(2,2,1);mesh(x,y,z);% do thi mesh title('mesh')% gan chu thich mesh subplot(2,2,2);surf(x,y,z)% do thi surf title('surf') subplot(2,2,3);contour(x,y,z) title('contour')%do thi duong dong muc contour subplot(2,2,4);contour3(x,y,z) title('contour3')%do thi duong dong muc 3chieu Bai 5 % Cau a subplot(2,2,1); [teta,phi]=meshgrid(0:pi/30:pi, 0:pi/30:2*pi); x0=0;y0=0;z01=-1;z02=1;r=1; x1=x0+r*cos(phi).*sin(teta); y1=x0+r*sin(phi).*sin(teta); z11=z01+r*cos(teta); z12=z02+r*cos(teta); mesh(x1,y1,z11);hold on mesh(x1,y1,z12); % Cau b subplot(2,2,2);R=2;r=0.25; [teta,phi]=meshgrid(0:pi/30:2*pi); x=(R+r*cos(teta)).*cos(phi) y=(R+r*cos(teta)).*sin(phi) z=r*sin(teta);mesh(x,y,z); % Cau c subplot(2,1,2); a1=[0,1/sqrt(3),-1/2*sqrt(3)]; b1=[0,0,1/2];c1=[sqrt(2/3),0,0]; fill3(a1,b1,c1,'r');hold on; a2=[1/sqrt(3),-1/2*sqrt(3),-1/2*sqrt(3)]; b2=[0,1/2,-1/2];c2=[0,0,0]; fill3(a2,b2,c2,'y'); a3=[-1/2*sqrt(3),-1/2*sqrt(3),0]; b3=[1/2,-1/2,0];c3=[0,0,sqrt(2/3)]; fill3(a3,b3,c3,'g'); a4=[-1/2*sqrt(3),0,1/sqrt(3)]; b4=[-1/2,0,0];c4=[0,sqrt(2/3),0]; fill3(a4,b4,c4,'r'); Bai 6: function t=bai6(n,x) if (n<0)|(n~=round(n))% n khac gia tri da lam tron cua n fprintf('So n nhap vao khong phai la so nguyen duong') elseif n==0 t=1; elseif n==1 t=x; else t=2.*x.*bai6(n-1,x)-bai6(n-2,x); end % Cau b;x=-1:0.01:1 t0=bai6(0,x)% tinh gia tri T0; plot(x,t0);hold on t1=bai6(1,x);plot(x,t1,'r');hold on t2=bai6(2,x);plot(x,t2,'d');hold on t3=bai6(3,x);plot(x,t3,'y');hold on %den day ko chay dc??? 2 Cao V¨n ChÝnh_B1K52 t4=bai6(4,x);plot(x,t4,'b');hold on t5=bai6(5,x);plot(x,t5,'g');hold off; legend('t0','t2','t3','t4','t5')% gan nha~n cua do thi % Cau c figure(2) % Cau c x=linspace(-1,1); plot(x,bai6(4,x));ylim([-1.5 1.5])%gioi han do thi [x0,y0]=ginput;% lay toa do = cach click chuot f=inline('bai6(4,x)','x');% de y vao ham nay khi tim khong diem for k=1:length(x0);%do rong cua khong diem [xn(k) fxn(k)]=fzero(f,x0(k));%ham tim khong diem thuc fzero text(xn(k),fxn(k),'< 0 diem')% end % Tim cac max [x1,y1]=ginput; f1=inline('(-1)*bai6(4,x)','x'); for i=1:length(x1); [xn(i) fxn(i)]=fminsearch(f1,x1(i)); text(xn(i),(-1)*fxn(i),'< max')%chu y co -1 end % Tim cac min [x1,y1]=ginput; f1=inline('bai6(4,x)','x'); for i=1:length(x1); [xn(i) fxn(i)]=fminsearch(f1,x1(i));% ham tim cuc tieu text(xn(i),fxn(i),'< min') end Bai 7 function [x0,fx0,n,xn,fxn]=bai7(a,b,fx,dfx,tol); %tol la nhap so lieu dang sai so %thay vi lap dao ham cua fx ta tinh luon dfx fx=inline(fx);dfx=inline(dfx);%inline la %1 ham moi ma minh tu dat no dang nhu 1 %function hoac @ ham xi=linspace(a,b,100); yi=subs(fx,'x',xi);%ham dao bien plot(xi,yi,'r');grid on [x0,fx0]=ginput(5); for i=1:length(x0) xn(i)=x0(i);%dau ra xn n(i)=0; k(i)=fx(x0(i))./dfx(x0(i));%chu y chuyen ve while abs(k(i))<= tol%dieu kien cua tri tuyet doi xn(i)=xn(i)-k(i); k(i)=fx(xn(i))./dfx(xn(i)); n(i)=n(i)+1;% n dau ra thu i end; fxn(i)=fx(xn(i));%dau ra fxn thu i end %Phan b ra cua so window command de goi an % cau b [x0,fx0,n,xn,fxn]=bai7(0,3,'x-sin(x)-1','1-cos(x)',10^(-10)) [x0,fx0,n,xn,fxn]=bai7(1,5,'(log(x))^2-x^2 + 2*x + 3 ','2*log(x)/x - 2*x + 2',10^(-10)) [x0,fx0,n,xn,fxn]=bai7(0,5,'exp(-x)-sin(x^2)-0.5','-exp(-x)-2*cos(x^2)*x',1e-10) Bai 8 close all;clc [x,y]=meshgrid(-2:.2:2,0:.2:2); z1=(x.^2).*sin(y)+cos(2*x).*y-0.5; z2=(2.^x).*y-x.*(y.^2)-1; contour(x,y,z1,[0 0],'r');hold on contour(x,y,z2,[0 0],'b') f=inline('[(x(1)^2)*sin(x(2))+cos(2*x(1))*x(2)-0.5;(2^x(1))*x(2)-x(1)*(x(2)^2)-1]','x'); %x(1)=x;x(2)=y,ham f lay chuan hoa [x0 y0]=ginput;;%ginput la ham truy nhap bang chuot lay ket qua tu do thi 3 Cao V¨n ChÝnh_B1K52 for k=1:length(x0)%ham fsolve la ham lay chinh xac nghiem [xn,yn]=fsolve(f,[x0(k) y0(k)]); end fprintf(' Cac cap nghiem cua phuong trinh 1 la:\n'); %fprintf la ham hien thi ra man hinh comand window xn,yn % Cau b %luu sang editor khac figure(2) [x,y]=meshgrid(-2:.2:2); z=x+i*y;%z la bieu thuc phuc f=z.^2+cos(log(abs(z)+1)+3)-2.^z-i; contour(x,y,real(f),[0 0],'r');hold on% ve theo phan thuc contour(x,y,imag(f),[0 0],'b');hold off% ve theo phan ao [x0,y0]=ginput; z0=x0+i*y0; fz=inline('z^2+cos(log(abs(z)+1)+3)-2^z-i','z'); for k=1:length(z0) [zn,fzn]=fsolve(fz,z0(k)) end fprintf(' Cac cap nghiem cua phuong trinh 2 la:\n'); zn fzn Bai 9 % phan a clear all R=1 r=R.*sin(pi/10)./cos(pi/5) k=0:9; x=R.*sin(k.*pi./5).*((-1).^k==1)+r.*sin(k.*pi./5).*((-1).^k==-1); y=R.*cos(k.*pi./5).*((-1).^k==1)+r.*cos(k.*pi./5).*((-1).^k==-1); disp('Toa do dinh ngoai') k=1:2:9;% cho k chay tu 1 toi 9 voi buoc nhay la 2 xt=x(k)% toa do theo truc x yt=y(k)%toa do theo truc y disp('Toa do dinh trong') k=1:2:9; xt=x(k+1) yt=y(k+1) % Muon ve hinh tron p=linspace(0,2*pi,300); R=1 x1=R.*cos(p); y1=R.*sin(p); figure(1) fill(x1,y1,'r') hold on fill(x,y,'y') axis equal % ve quoc ky figure(2) fill([2.5 -2.5 -2.5 2.5],[2 2 -2 -2],'r') hold on fill(x,y,'y') Bai 10 clear i w=linspace(1e+3,1e+5)% tan so goc w R=10 C1=1e-6 C2=0.1e-6 L=1e-3 ZL=L*2*pi*w*i ZC1=1./(2*pi*w*C1)*i ZC2=1./(2*pi*w*C2)*i ZLC2=ZL.*ZC2./(ZL+ZC2) G=ZLC2./(R+ZC1+ZLC2) subplot(2,2,1);plot(w,real(G));legend('Dothi Re(G)');%ve theo w va phan thuc 4 Cao V¨n ChÝnh_B1K52 subplot(2,2,2);plot(w,imag(G));legend('Dothi Im(G)');%ve theo w va phan ao subplot(2,2,3);plot(w,abs(G));legend('Do thi |G|');%ve theo w va tri tuyet doi subplot(2,2,4);plot(w,angle(G));legend('Do thi Arg(G)');%ve theo w va goc pha Bai 11 L p bi u th c tính Pn: còn tính t P0-ậ ể ứ ừ  P5 làm t ng t nh bài 6bươ ự ư ở function t=bai11a(n,x) if (n<0)|n~=round(n) fprintf('Hay nhap lai n nguyen duong') elseif n==0 t=1; elseif n==1 t=x; else t=(2*n-1)/n*x*bai11a(n-1,x)-(n-1)/n*bai11a(n-2,x); end %Bai11B function tong=bai11b(n,x); if (n<0|n~=round(n)) disp('xin hay nhap lai so nguyen duong') elseif n==0 tong=1; elseif n==1 tong=x; else giaithua=1; for k=1:n; giaithua=giaithua*k; end tong=(1./(giaithua*2^n)).*diff((x^2-1)^n,n); end % Cau c %chua chay duoc h=(1-x.^2).*diff(p1(n),x,2)-2.*x.*diff(p1(n),x)+n*(n+1)*p1(n) i=quad(p1(n).^2,-1,1)-2/2*n+1 k=quad(p1(6)*p1(n).^2,-1,1) Bai 12 % Cau a% ve mat cong [x,y]=meshgrid(-5:.6:5); z=(2.*x.^2+3.*y.^2).*exp(-(x.^2+y.^2)) figure(1) subplot(2,2,1) mesh(x,y,z) % Cau b% tinh truong vecto va ve chung [dzx,dzy]=gradient(z) subplot(2,2,2) quiver(x,y,dzx,dzy) %dz=sqrt(dzx.^2+dzy.^2) %subplot(2,2,3) %quiver(x,y,dzx./dz,dzy./dz) % Cau c% tim cuc tri %Tim cuc tieu subplot(2,2,4) contour(x,y,z);shg [xo yo]=ginput f=inline('(2.*x(1).^2+3.*x(2).^2).*exp(-(x(1).^2+x(2).^2))','x') for i=1:length(xo) [ct(i,:) fct(i,:)]=fminsearch(f,[xo(i) yo(i)]) end ct,fct %Tim cuc dai [x1 y1]=ginput f1=inline('(-1)*(2.*x(1).^2+3.*x(2).^2).*exp(-(x(1).^2+x(2).^2))','x') for j=1:length(x1) [cd fcd]=fminsearch(f1,[x1(j) y1(j)]) end cd, (-1)*fcd %chu y nhan -1 voi fcd Bai 13 (Chua hiu) 5 Cao V¨n ChÝnh_B1K52 %cau a clc A01=[19 -9 -6;25 -11 -9;17 -9 -4]; A02=[-1 4 -2;-3 4 0;-3 1 3]; A=A02;% Thay A01 bang A02 de tinh cho ma tran thu 2 [P,a]=eig(A);A,P fprintf('P^(-1)*A*P=\n');disp(inv(P)*A*P) % Cau b f=inline('5*x^2-4*x*y+8*y^2+20/sqrt(5)*x-80/sqrt(5)*y+4','x','y'); ezplot(f,[-4 4 -2 6]);shg % Cau c function [A1,b1,c1,V,T]=bai13c(A,b,c) [V,A1]=eig(A); a=diag(A1); b1=b*V; c1=c; for k=1:length(a); if a(k)~=0 T(k)=-b1(k)/(2*a(k)); c1=c1-b1(k)^2/(4*a(k)); b1(k)=0; end end % Thu lai cho cau b clc A=[5 -2;-2 8]; b=[20/sqrt(5) -80/sqrt(5)]; c=4; [A1,b1,c1,V,T]=bai13c(A,b,c); syms x y; XY=[x y]; pt=XY*A1*(XY.')+b1*(XY.')+c1;pretty(pt) ezplot(pt) % Cau d syms T D=[T 1 1;1 T 1;1 1 T]; b=[1;T;T^2]; Dx=[b D(:,2) D(:,3)]; Dy=[D(:,1) b D(:,3)]; Dz=[D(:,1) D(:,2) b]; d=det(D); dx=det(Dx); dy=det(Dy); dz=det(Dz); ng=solve(d,T); % Don gian nghiem xx=[]; for i=1:length(ng) t=0; for j=1:length(xx) if ng(i)==xx(j); t=t+1; end end if t==0 xx=[xx ng(i)]; end end ng=xx;vd=[];vn=[]; for i=1:length(ng); if (subs(dx,'T',ng(i))==0)|(subs(dy,'T',ng(i))==0)|(subs(dz,'T',ng(i))==0) vd=[vd,ng(i)]; else vn=[vn,ng(i)]; end end fprintf('Phuong trinh vo dinh voi T='); for i=1:length(vd); disp(vd(i)) 6 Cao V¨n ChÝnh_B1K52 end fprintf('Phuong trinh vo nghiem voi T='); for i=1:length(vn); disp(vn(i)) end fprintf('PT co nghiem duy nhat voi T khac');disp(ng) fprintf(' x=');disp(dx/d) fprintf(' y=');disp(dy/d) fprintf(' z=');disp(dz/d) Bai 14 %Cau a syms z x=sqrt(5*pi/2-z).*cos(sqrt(5*pi/2-z))+pi dx=diff(x,z) f=inline('dx') l=quad(f,0,2*pi)%Tinh chieu dai cung %Cau b %Tinh dien tich xung quanh x1=x.*(sqrt(1+dx)) f1=inline('x1') s=2*pi*quad(f1,0,2*pi) %Tinh the tich xoay quanh Oz x2=x.^2 f2=inline('x2') v=pi*quad(f2,0,2*pi) %Tinh the tich xoay quanh Ox x3=z.*x f3=inline('x3') v1=2*pi*quad(f3,0,2*pi) %Cau c ezplot(x3,[0 2*pi]) Bai 15 clear all;clc;close all syms x a=input('nhap a='); Io=input('nhapIo='); d=sqrt(x.^2+a^2); I=Io.*x./d.^3; dt=diff(I,x); f1=diff(I,x,2); x0=solve(dt,x) f2=subs(f1,x,x0) for k=1:length(f2) if double(f2(k))<0 xcd=x0(k); end end xcd Icd=subs(I,x,xcd) Bai 16 %Cau a: Chu y luu ra 1 editor khac,luu voi ten: bai16a function t=bai16a(n) if n==0 t=[0 1] elseif n==1 t=[1 0] else n>1 t=polyadd(2*conv([1 0],s(n-1)),-s(n-2)) end; t %Cau b: luu ra 1 editor khac lay ten la:bai16b function s=bai16b(a,b) na=length(a); nb=length(b); 7 Cao V¨n ChÝnh_B1K52 s=[zeros(1,(na-nb)),b]+[zeros(1,(nb-na)),a] %Luu doan code nay sang editor khac, ten file la gi cung dc figure(1);x=-1:.1:1; plot(x,bai16b(bai16a(0),x),'r');hold on plot(x,bai16b(bai16a(1),x),'m');hold on %cach 2 function T=bai16(n,x); if n<0 |n~=round(n) fprintf('Nhap lai n khong am'); elseif n==0 T=1; elseif n==1 T=x; else T=2.*x.*bai16(n-1,x)-bai16(n-2,x); end clear;clc; x=linspace(-1,1,100); T0=bai16(0,x)% tinh gia tri T0 plot(x,T0);hold on T1=bai16(1,x) plot(x,T1,'r');hold on T2=bai16(2,x) plot(x,T2,'d');hold on T3=bai16(3,x) %den cho nay ko chay dc, chua hiu tai sao????? plot(x,T3,'dr');hold on T4=bai16(4,x) plot(x,T4,'b');hold off legend('T0','T2','T3','T4','T5')% gan nha~n cua do thi Bai 17 (chua chay dc) % cau a function s=bai17(xj,t) ts=1; for k=1:length(xj) if k~=t ts=conv(polyadd([1 0],[0 -xj(k)]),ts); end end ms=polyval(ts,xj(t)); s=ts/ms %phan b xj=-2:.5:2;t=-2:.2:2; mau='rmgcbk';so='123456'; close all for i=1:5 plot(t,polyval(bai17(xj,i),t),mau(i)) text(-1.8,polyval(bai17(xj,i),-1.8),so(i));hold on end Bai 18 %Doc lai bai tim tiem can cua do thi ham so close all; clear; clc; syms x; f1=abs(x.^3+x+1)-3; f2=x.^2-x-6; f=f1/f2 + x; yi=linspace(-30,30,100); ezplot(f,[-10 10]);axis ([-10 10 -30 30]);hold on; [x0,fx0]=ginput; fx=inline(char(f),'x');% cach 2 fx=inline('(abs(x.^3+x+1)-3)/(x.^2-x-6) + x','x'); for k=1:length(x0); [xn(k,:)]=fsolve(fx,x0(k)); end xn 8 Cao V¨n ChÝnh_B1K52 xv=solve(f2);% tim tiem can dung fprintf(['Tiem can dung cua do thi ham so:x=',char(xv(1)),' Va ','x=',char(xv(2)),'\n']); yv=limit(f,x,-inf);%tim tiem can ngang fprintf(['Tiem can ngang cua do thi ham so:y=',char(yv),'\n']); a=limit(f./x,x,inf);%tim tiem can xien b=limit(f-a*x,x,inf); fprintf(['Tiem can xien cua do thi ham so:y=',char(a),'x + ',char(b),'\n']); plot(double(xv(1)*ones(size(yi))),yi,'r') ;% cach 2 :plot(double(xv(1)),yi,'r') plot(double(xv(2)*ones(size(yi))),yi,'r') ;% cach 2 :plot(double(xv(2)),yi,'r') xi=(yi-1)/2;plot(xi,yi,'r'); plot(xi,double(-1*ones(size(xi))),'r');% %cach 2 :plot(xi,-1,'r'); hold off; Bai 19 % Bai tap so 19% a1=[1 2 3;4 5 6; 7 8 9]; a2=[1 1 3;4 5 6;7 8 9]; a3=[0.9999 2 3;4 5 6;7 8 9] b1=[1 1 3] b11=b1(:) b2=[1 2 3] b21=b2(:)%Dua vecto hang thanh cot % Lam vi du voi a1% det(a1)%Tim dinh thuc ma tran inv(a1)%Tim nghich dao ma tran diag(a1)%Tim duong cheo ma tran a=poly(a1)%Tim he so da thuc dac trung p=poly2sym(a)%Tim da thuc dac trung N=null(a1)%Ma tran chua n vector cuakhong gian 0 v=eig(a1)%Tim tri rieng cua ma tran [v,d]=eig(a1)%v:ma tran lam cheo; d: dang cheo a1 n=size(N,2)%So chieu cua khong gian khong rank(a1)%Tim hang ma tran % A1=[1 2 3;4 5 6;7 8 9]; A2=[1 1 3;4 5 6;7 8 9]; A3=[0.9999 2 3;4 5 6;7 8 9]; b1=[1;1;3];b2=[1;2;3]; %tinh chuan cua cac vector b1,b2 va cuacac ma tran A1,A2,A3 fprintf('Chuan cua cac vector b1 & b2 va cua cac ma tran A1,A2,A3la:\n') norb1=norm(b1) norb2=norm(b2) norA1=norm(A1) norA2=norm(A2) norA3=norm(A3) fprintf('Dinh thuc cua ma tranA1,A2,A3:\n') % Tinh dinh thuc cua ma tran dung 'det' detA1=det(A1) detA2=det(A2) detA3=det(A3) if det(A1)==0 fprintf('Dinh thuc ma tran A= 0\n'); fprintf('Do do khong co ma tran nghic dao\n') else fprintf('Dinh thuc ma tran A=');disp(det(A1)) fprintf('Ma tran nghich dao cua A\n');disp(inv(A1)); end if det(A2)==0 fprintf('Dinh thuc ma tran A= 0\n'); fprintf('Do do khong co ma tran nghic dao\n') else fprintf('Dinh thuc ma tran A=');disp(det(A2)) 9 Cao V¨n ChÝnh_B1K52 fprintf('Ma tran nghich dao cua A\n');disp(inv(A2)); end if det(A3)==0 fprintf('Dinh thuc ma tran A= 0\n'); fprintf('Do do khong co ma tran nghic dao\n') else fprintf('Dinh thuc ma tran A=');disp(det(A3)) fprintf('Ma tran nghich dao cuaA\n');disp(inv(A3)); end % % Tinh ma tran nghich dao dung 'inv' % fprintf('Ma tran nghich dao :\n') % invA1=inv(A1) % invA2=inv(A2) % invA3=inv(A3) %Tinh tri rieng cua cac ma tran dung 'eig' [V1,d1]=eig(A1) %tri rieng d1, Vectorrieng V1 [V2,d2]=eig(A2) [V3,d3]=eig(A3) fprintf('Tri rieng d1:\n') disp(d1) fprintf('Tri rieng d2:\n') disp(d2) fprintf('Tri rieng d3:\n') disp(d3) fprintf('Vector rieng V1:\n') disp(V1) fprintf('Vector rieng V1:\n') disp(V2) fprintf('Vector rieng V1:\n') disp(V3) %Xac dinh da thuc dac trung cua cac ma tran A1,A2,A3 fprintf('Da thuc dac trung cua cac ma tran A1,A2,A3') dactrungA1=poly(A1) dactrungA2=poly(A2) dactrungA3=poly(A3) Bai 20 % Lap function de giai function [ln,x]=bai20(A,b) if (rank(A)==rank([A,b]))&(rank(A)==size(A,1)) ln='Pt co nghiem duy nhat'; x=A\b ; elseif (rank(A)==rank([A,b]))&(rank(A)<size(A,1)) ln='Pt Vo so nghiem'; syms x1 c; x0=null(A);% Nghiem pt thuan nhat xc1=solve((A(1,1)+A(1,2))*x1+A(1,3)-b(1),x1); xc=[xc1 xc1 1].'; x=c*x0+xc; else ln='Pt Vo nghiem voi tua nghiem'; x=pinv(A)*b; end %sang editor moi %cau a b c clc A1=[1 2 3;4 5 6;7 8 9]; A2=[1 1 3;4 5 6;7 8 9]; A3=[0.999 2 3;4 5 6;7 8 9]; b1=[1 1 3].'; b2=[1 2 3].'; [ln,x11]=bai20(A1,b1) [ln,x12]=bai20(A1,b2) [ln,x21]=bai20(A2,b1) 10 [...]... subplot(2,1,1); ezplot(y1b,[0 1]);grid on;hold on ezplot(y2b,[0 1]); Tổng hợp code các đề thi Matlab De 1: clc;close all;clear all %cau a %luoi 41 chia deu [x,y]=meshgrid(linspace(-2,2,41)); z=8./(x.^4+y.^4+2.*x+2.*y+4)-exp(-x.^2-y.^2+x+y+1); %cau b %tim chi so hang i, cot j, . Cao V¨n ChÝnh_B1K52 Tổng hợp code các bài thực hành Matlab Bai 1 clc x=-2:0.01:2 y=exp(-0.3.*x.^2- 0.5.*x +1).*cos(20.*x) subplot(2,1,1)%. figure(2); subplot(2,1,1); ezplot(y1b,[0 1]);grid on;hold on ezplot(y2b,[0 1]); Tổng hợp code các đề thi Matlab De 1: clc;close all;clear all %cau a %luoi 41 chia deu [x,y]=meshgrid(linspace(-2,2,41));. Arg(G)');%ve theo w va goc pha Bai 11 L p bi u th c tính Pn: còn tính t P0-ậ ể ứ ừ  P5 làm t ng t nh bài 6bươ ự ư ở function t=bai11a(n,x) if (n<0)|n~=round(n) fprintf('Hay nhap lai n nguyen

Ngày đăng: 02/04/2014, 15:46

TỪ KHÓA LIÊN QUAN

w