Matlab程序设计与应用第二版刘卫国
实验
T1:
%%第一小题
z1=2*sin(85*pi/180)/(1+exp(2))
%%第二小题x=[2,1+2i;-0.45,5];
z2
%%第三小题
a=-3.0:0.1:3.0;
0.3)+log((0.3+a)/2)
%%第四题
t=0:0.5:2.5
z4=(t>=0&t<1).*(t.A2)+(t>=1 &t<2).*(t 八2-1)+(t>=2&t<3).*(t.A2-2*t+1)
T2:
A=[12,34,-4;34,7,87;3,65,7]
B=[1,3,-1;2,0,3;3,-2,7]
disp ('A+6*B=');
disp(A+6*B);
disp('A-B+I=');disp(A-B+eye(3)); disp('A*B=');
disp(A*B);
disp('A.*B=');
disp(A.*B);
disp('A A3=');
disp(AT);
disp('A.A3二');
disp(A.A3);
disp('A/B=');
disp(A/B);
disp('B\A=');
disp(B\A);
disp('[A,B]=');
disp([A,B]);
disp('[A([1,3],:);BA2]=');
disp([A([1,3],:);BA2]);
T3:
z=1:25;
A=reshape(z,5,5)';
B=[3,0,16;17,-6,9;0,23,-4;9,7,0;4,13,11];C=A*BD=C(3:5,2:3) T4-1:
a=100:999;
b=find(rem(a,21)==0);
c=length(b)
T4-2:
a=input(' 请输入一个字符串:','s');
b=find(a>='A'&a<='Z');
a(b)=[];
disp(a);
实验二:
T1:
E=eye(3),R=rand(3,2),O=zeros(2,3),S=d iag([1,2]); A=[E,R;O,S]
disp('A A2=');
disp(AT);
disp('[E,R+RS;0,SA2]');
B二[E,R+R*S;0,SA2]
T2:
H=hilb(5)
P=pascal(5)Hh=det(H)
Hp=det(P)
Th=cond(H)
Tp=cond(P)
a=abs(Th-1);
b=abs(Tp-1);
if a>b
disp('帕萨卡矩阵P性能更好');elseif a
disp('希尔伯特矩阵H性能更好');else
disp('两个矩阵性能相同');
end
T3:
a=1:25;
A=reshape(a,5,5)
d i s p ( '行列式的值:');
disp(det(A));
disp('矩阵的秩:');
disp(rank(A));
disp('矩阵的迹:');
disp(trace(A));disp('矩阵的范数:'); disp(norm(A)); T4:
A=[-29,6,18;20,5,12;-8,8,5]
[V,D]=eig(A)
T5:
B=[0.95,0.67,0.52]'
B(3)=0.53
X2=A\B
disp('系数矩阵A的条件数:’); disp(cond(A)); T6:
a=1:25;
A=reshape(a,5,5)
disp('B1=sqrtm(A)');
B1=sqrtm(A)
disp('B2=sqrt(A)');
B2=sqrt(A)
disp('B1*B1');
B1*B1disp('B2.*B2');
B2.*B2
实验三:
T1:
x=-5.0:2:5.0
for i=1:length(x);
if (x(i)<0)&(x(i)~=-3)
y(i)=x(i)八2+x(i)-6;
(x(i)>=0)&(x(i)<5)&(x(i)~=2)&(x(i)~=3);
y(i)=x(i)A2-5*x(i)+6;
else
y(i)=x(i)A2-x(i)-1;
end
end
y
T2-if:
s=input('please enter the score:');while (s<0||s>100)
disp('the score is not reasonable');s=input('please enter the score:'); end
if (s>=90&s<=100);
disp('A'); elseif(s>=80&s<90);
disp('B'); elseif(s>=70&s<80);
disp('C');
elseif(s>=60&s<70);
disp('D');
else
disp('E');
end
T2-switch:
s=input('please enter the score:'); while (s<0||s>100) disp('the score is not reasonable'); s=input('please enter the score:'); end
switch fix(s/10)
case{9,10}
disp('A');
case{8}disp('B');
case{7} disp('C');
case{6} disp('D');
case{0,1,2,3,4,5} disp('E');
end
T3: t=input(' 请输入工时time=');
if t>120
w=120*84+(t-120)*1.15*84;elseif t<60 w=t*84-700;
else
w=84*t;
end
disp('应发工资为:');
disp(w);
T4:
a=10+floor(rand(1)*89)