câu4
function bai4
n= input ('Nhap n:');
m= input ('Nhap m:');
for i=1:n
for j=1:m
a(i,j)=input(['Nhap a',num2str(i),'(',num2str(j),')= ']);
end
disp(a(i,:))
end
i=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;
end
i=i+1;
end
if k==1
disp('Trong cac day so nay co it nhat 2 day so giong nhau')
else
disp('Trong cac day so nay ko co day so nao giong nhau')
end
câu5
function bai5
n= input('Nhap n: ');
j=0;
B=[];
for i=1:n
A(i)=input(['Nhap A(',num2str(i),'): ']);
if rem(A(i),7)==0
j=j+1;
B(j)=A(i);
end
end
m=size(B,2);
if m>0
max=B(1);
for i=1:m
if max < B(i)
max=B(i)
end
end
disp(['So lon nhat cua day so B la: ',num2str(max)])
else
disp('Trong day so A ko co so nao chia het cho 7')
end
câu6
function bai6
a1= input('Nhap a1: ');
a2= input('Nhap a2: ');
b1= input('Nhap b1: ');
b2= input('Nhap b2: ');
i=0;
while i==0
R1=input('Nhap R1: ');
if R1 > 0
i=1;
else
disp('* Ban da nhap sai yeu cau nhap lai R1 *')
end
end
i=0;
while i==0
R2=input('Nhap R2: ');
if R2 > 0
i=1;
else
disp('* Ban da nhap sai yeu cau nhap lai R2 *')
end
end
x1=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 on
plot(x1,y1);
plot(x1,y2);
plot(x2,y3);
plot(x2,y4);
axis equal;
Câu7
function bai7
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: ');
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 on
plot(x,y2,'b-')
plot(x,y3,'g--')
plot(x,y4,'r:')
câu8
function bai8
a= 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 on
plot(x,y1);
plot(x,y2);
subplot(1,2,2)
hold on
plot(x,y2);
plot(x,y3);
Câu9
function bai9
a= 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âu10
function bai10
i=0;
while i==0
x=input('Nhap x: ');
if (2.5<x) & (x<3.2)
i=1;
else
disp('* Ban da nhap sai x yeu cau nhap lai *')
end
end
i=0;
while i==0
C1=input('Nhap C1: ');
C2=input('Nhap C2: ');
C3=input('Nhap C3: ');
if (C1>C2) & (C2>C3)
i=1;
else
disp('* Ban da nhap sai cac he so C yeu cau nhap lai *')
end
end
n=linspace(0,100,1000);
Ne1=C1*n.^x;
Ne2=C2*n.^x;
Ne3=C3*n.^x;
hold on
plot(n,Ne1)
plot(n,Ne2)
plot(n,Ne3)
câu11
function bai11
a2= 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âu12
function bai12
n=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;
end
for i=1:(n+1)
a(i)= input(['Nhap a',num2str(i-1)]);
A=a(i)*(j*w).^(i-1)+A;
end
G=A./B
R=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âu13
function bai13
disp(' 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âu14
function bai14
x1= 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 on
fplot('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âu15
function bai15
syms 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âu16
function bai16
syms 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âu17
function bai17
syms t
x=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: Truyen4U.Com