Dap An Matlab
câu4function bai4n= input ('Nhap n:');m= input ('Nhap m:');for i=1:nfor j=1:ma(i,j)=input(['Nhap a',num2str(i),'(',num2str(j),')= ']); enddisp(a(i,:))endi=1;k=0;while (i<=n-1) & (k==0)j=i+1;while (j<=n) & (k==0)k= isequal(a(i,:),a(j,:));j=j+1;endi=i+1;endif k==1disp('Trong cac day so nay co it nhat 2 day so giong nhau')elsedisp('Trong cac day so nay ko co day so nao giong nhau')endcâu5function bai5n= input('Nhap n: ');j=0;B=[];for i=1:nA(i)=input(['Nhap A(',num2str(i),'): ']);if rem(A(i),7)==0j=j+1;B(j)=A(i);endendm=size(B,2);if m>0max=B(1);for i=1:mif max < B(i)max=B(i)endenddisp(['So lon nhat cua day so B la: ',num2str(max)])elsedisp('Trong day so A ko co so nao chia het cho 7')endcâu6function bai6a1= input('Nhap a1: ');a2= input('Nhap a2: ');b1= input('Nhap b1: ');b2= input('Nhap b2: ');i=0;while i==0R1=input('Nhap R1: ');if R1 > 0i=1;elsedisp('* Ban da nhap sai yeu cau nhap lai R1 *')endendi=0;while i==0R2=input('Nhap R2: ');if R2 > 0i=1;elsedisp('* Ban da nhap sai yeu cau nhap lai R2 *') endendx1=linspace(-a1-R1,-a1+R1,100);x2=linspace(-a2-R2,-a2+R2,100);y1= ((R1^2 - (x1+a1).^2)).^(1/2) - b1;y2= -((R1^2 - (x1+a1).^2)).^(1/2) - b1;y3= ((R2^2 - (x2+a2).^2)).^(1/2) - b2;y4= -((R2^2 - (x2+a2).^2)).^(1/2) - b2;hold onplot(x1,y1);plot(x1,y2);plot(x2,y3);plot(x2,y4);axis equal;Câu7function bai7disp(' Nhap cac he so cua phuong trinh bac hai:')a2= input(' Nhap a2: ');b2= input(' Nhap b2: ');c2= input(' Nhap c2: ');disp(' Nhap cac he so cua phuong trinh bac ba:')a3= input(' Nhap a3: ');b3= input(' Nhap b3: ');c3= input(' Nhap c3: ');d3= input(' Nhap d3: ');disp(' Nhap cac he so cua phuong trinh bac bon:')a4= input(' Nhap a4: ');b4= input(' Nhap b4: ');c4= input(' Nhap c4: ');d4= input(' Nhap d4: ');e4= input(' Nhap e4: ');x=linspace(-10,10,100);y2= a2*x.^2+ b2*x +c2;y3= a3*x.^3+ b3*x.^2 +c3*x+d3;y4= a4*x.^4+ b4*x.^3 +c4*x.^2+ d4*x+e4;hold onplot(x,y2,'b-')plot(x,y3,'g--')plot(x,y4,'r:')câu8function bai8a= input(' nhap a:');b= input(' nhap b:');x=linspace(-10,10,100);y1=a*cos(x) + b* sin(x) ;y2=cos(a*x)+sin(b*x) ;y3=(a*cos(x)+b*sin(x))./(cos(a*x)+sin(b*x)) ;y4=(cos(a*x)+sin(b*x))./(a*cos(x)+b*sin(x)) ;subplot(1,2,1)hold onplot(x,y1);plot(x,y2);subplot(1,2,2)hold onplot(x,y2);plot(x,y3);Câu9function bai9a= input(' nhap a:');b= input(' nhap b:');c= input(' nhap c:');d= input(' nhap d:');e= input(' nhap e:');f= input(' nhap f:');xmin=input('Nhap xmin:');xmax=input('Nhap xmax:');x=linspace(xmin,xmax,100);y1=sin(a*x); y2=cos(b*x); y3=sin(c*x)./cos(d*x); y4=sin(e*x).*cos(f*x);subplot(2,2,1)plot(x,y1)title('sin(x)');subplot(2,2,2)plot(x,y2)title('cos(x)');subplot(2,2,3)plot(x,y3)title('sin(x)/cos(x) ');subplot(2,2,4)plot(x,y4)title('sin(x)*cos(x)');câu10function bai10i=0;while i==0x=input('Nhap x: ');if (2.5<x) & (x<3.2)i=1;elsedisp('* Ban da nhap sai x yeu cau nhap lai *')endendi=0;while i==0C1=input('Nhap C1: ');C2=input('Nhap C2: ');C3=input('Nhap C3: ');if (C1>C2) & (C2>C3)i=1;elsedisp('* Ban da nhap sai cac he so C yeu cau nhap lai *')endendn=linspace(0,100,1000);Ne1=C1*n.^x;Ne2=C2*n.^x;Ne3=C3*n.^x;hold onplot(n,Ne1)plot(n,Ne2)plot(n,Ne3)câu11function bai11a2= input('Nhap a2');b2= input('Nhap b2:');c2= input('Nhap c2:');a3= input('Nhap a3:');b3= input('Nhap b3:');c3= input('Nhap c3:');d3= input('Nhap d3:');w=linspace(0,100,1000);R2=c2-a2*w.^2;Q2=b2*w;R3=d3-b3*w.^2;Q3=c3*w-a3*w.^3;subplot(2,1,1)plot(R2,Q2)subplot(2,1,2)plot(R3,Q3)câu12function bai12n=input('Nhap n:');m=input('Nhap m:');w=linspace(0,100,1000);B=0;A=0;for i=1:(m+1)b(i)= input(['Nhap b',num2str(i-1)]);B=b(i)*(j*w).^(i-1)+B;endfor i=1:(n+1)a(i)= input(['Nhap a',num2str(i-1)]);A=a(i)*(j*w).^(i-1)+A;endG=A./BR=real(G);Q=imag(G);C=(R.^2+Q.^2).^(1/2)phi=arctan(Q/R)subplot(2,1,1)plot(w,20*log(C))subplot(2,2,1)plot(w,phi)câu13function bai13disp(' Nhap cac he so cua phuong trinh bac nhat:')a1= input(' Nhap a1: ');b1= input(' Nhap b1: ');disp(' Nhap cac he so cua phuong trinh bac hai:')a2= input(' Nhap a2: ');b2= input(' Nhap b2: ');c2= input(' Nhap c2: ');disp(' Nhap cac he so cua phuong trinh bac ba:')a3= input(' Nhap a3: ');b3= input(' Nhap b3: ');c3= input(' Nhap c3: ');d3= input(' Nhap d3: ');disp(' Nhap cac he so cua phuong trinh bac bon:')a4= input(' Nhap a4: ');b4= input(' Nhap b4: ');c4= input(' Nhap c4: ');d4= input(' Nhap d4: ');e4= input(' Nhap e4: ');disp(' Nhap cac he so cua phuong trinh bac nam:')a5= input(' Nhap a5: ');b5= input(' Nhap b5: ');c5= input(' Nhap c5: ');d5= input(' Nhap d5: ');e5= input(' Nhap e5: ');f5= input(' Nhap f5: ');x=linspace(-10,10,100);y1= a1*x+ b1*x;y2= a2*x.^2+ b2*x +c2;y3= a3*x.^3+ b3*x.^2 +c3*x+d3;y4= a4*x.^4+ b4*x.^3 +c4*x.^2+ d4*x+e4;y5= a5*x.^5+ b5*x.^4 +c5*x.^3+ d5*x.^2+e5*x+f5;subplot(1,5,1)plot(x,y1)subplot(1,5,2)plot(x,y2)subplot(1,5,3)plot(x,y3)subplot(1,5,4)plot(x,y4)subplot(1,5,5)plot(x,y5)câu14function bai14x1= input(' nhap can duoi cua x:');x2= input(' nhap can tren cua x:');disp(' Nhap cac he so cua phuong trinh bac hai:')a2= input(' Nhap a2: ');b2= input(' Nhap b2: ');c2= input(' Nhap c2: ');disp(' Nhap cac he so cua phuong trinh bac ba:')a3= input(' Nhap a3: ');b3= input(' Nhap b3: ');c3= input(' Nhap c3: ');d3= input(' Nhap d3: ');hold onfplot('sin(x)',[x1,x2]);fplot('cos(x)',[x1,x2]);fplot('tg(x)',[x1,x2]);fplot('a2*x.^2+ b2*x +c2;',[x1,x2]);fplot('a3*x.^3+ b3*x.^2 +c3*x+d3',[x1,x2]);câu15function bai15syms x t;x=sin(t)+cos(t)+1/tan(t)+tan(t)A=(cos(3*x) +sin(2*x))/(tan(x)+1/tan(x))*(x^3+4*x)/(10*sin(x))B=(sin(3*x)+cos(2*x))/(x^10+10*x^20)a1= input(' Nhap a1: ');b1= input(' Nhap b1: ');a2= input(' Nhap a2: ');b2= input(' Nhap b2: ');[A1,A2]=numden(A)[B1,B2]=numden(B)k1=int(A1,a1,b1)k2=int(B2,a2,b2)disp(['Tich phan cua tu so A la:',num2str(k1)])disp(['Tich phan cua tu so B la:',num2str(k2)])Câu16function bai16syms x;a1= input(' Nhap a1: ');b1= input(' Nhap b1: ');c1= input(' Nhap c1: ');d1= input(' Nhap d1: ');e1= input(' Nhap e1: ');a2= input(' Nhap a2: ');b2= input(' Nhap b2: ');c2= input(' Nhap c2: ');d2= input(' Nhap d2: ');A= a1*x^5 + b1*x^4 +c1*x^3 +d1*x^2 +e1*x;B= cos(a2*x) +sin(b2*x) +1/tan(c2*x) +tan(d2*x);disp('Cac nghiem cua bieu thuc A la:')solve(A)disp('Cac nghiem cua bieu thuc B la:')solve(B)subplot(1,2,1)ezplot(A)subplot(1,2,2)ezplot(B)câu17function bai17syms tx=tan(t);y= (1/tan(x)+ sin(x))^5 ; z= (sin(x) + cos(y))^10 ;A= 10*x^30 +sin(x) +cos (x); B= 10*y^40+1/tan(x)+tan(x);C=z^5 +z^4 + z^3 + z^2 + z;disp('Cac nghiem cua bieu thuc A la:')solve(A)disp('Cac nghiem cua bieu thuc B la:')solve(B)disp('Cac nghiem cua bieu thuc C la:')solve(C)subplot(1,3,1)ezplot(A)subplot(1,3,2)ezplot(B)subplot(1,3,3)ezplot(C)
Bạn đang đọc truyện trên: TruyenHHH.com