1
This commit is contained in:
10
lab4/exercise4_1.m
Normal file
10
lab4/exercise4_1.m
Normal file
@@ -0,0 +1,10 @@
|
||||
c = input('请输入一个字符:', 's');
|
||||
if c >= 'A' && c <= 'Z'
|
||||
disp(char(abs(c) + abs('a') - abs('A')));
|
||||
elseif c >= 'a' && c <= 'z'
|
||||
disp(char(abs(c) - abs('a') + abs('A')));
|
||||
elseif c >= '0' && c <= '9'
|
||||
disp(abs(c) - abs('0'));
|
||||
else
|
||||
disp(c);
|
||||
end
|
||||
6
lab4/exercise4_10.m
Normal file
6
lab4/exercise4_10.m
Normal file
@@ -0,0 +1,6 @@
|
||||
mysum=0,i=1;
|
||||
while(i<=100)
|
||||
mysum=mysum+i
|
||||
i=i+1 ;
|
||||
end
|
||||
mysum
|
||||
13
lab4/exercise4_11.m
Normal file
13
lab4/exercise4_11.m
Normal file
@@ -0,0 +1,13 @@
|
||||
A=[1 2 3;4 5 6;7 8 9];
|
||||
[r,c]=size(A);
|
||||
% 判断并把A中大于8和小于2的元素全部调整为0
|
||||
for i=1:1:r
|
||||
for j=1:1:c
|
||||
if (A(i,j)>8 || A(i,j)<2)
|
||||
A(i,j)=0;
|
||||
end
|
||||
end
|
||||
end
|
||||
% 改写
|
||||
b=(A <= 8 & A >= 2); % 判断A中小于等于8和大于等于2的元素,结果是逻辑值0/1
|
||||
A=A.*b %实现A中大于8和小于2的元素全部调整为0,基于矩阵的点乘
|
||||
5
lab4/exercise4_12.m
Normal file
5
lab4/exercise4_12.m
Normal file
@@ -0,0 +1,5 @@
|
||||
x = 0:0.05:2;
|
||||
y = diag(f(x).*f(x+2));
|
||||
plot(x,y);
|
||||
xlabel('\bfx');
|
||||
ylabel('\bfy');
|
||||
8
lab4/exercise4_13.m
Normal file
8
lab4/exercise4_13.m
Normal file
@@ -0,0 +1,8 @@
|
||||
subplot(2,2,2);
|
||||
x=linspace(-pi/2,pi/2,100);
|
||||
y=sqrt(cos(x));
|
||||
plot(x,y);
|
||||
subplot(2,2,3);
|
||||
x=linspace(-2,2);
|
||||
y=linspace(-4,4);
|
||||
ezsurfc('x.^2/4+y.^2/16')
|
||||
9
lab4/exercise4_14.m
Normal file
9
lab4/exercise4_14.m
Normal file
@@ -0,0 +1,9 @@
|
||||
A=input('请输入一个向量');
|
||||
[m,n]=size(A);
|
||||
min=A(1,n);
|
||||
for i=1:n
|
||||
if min>A(1,i)
|
||||
min=A(1,i);
|
||||
end
|
||||
end
|
||||
disp(min)
|
||||
6
lab4/exercise4_15.m
Normal file
6
lab4/exercise4_15.m
Normal file
@@ -0,0 +1,6 @@
|
||||
a=[2,3,1,2;1,3,0,1;1,-1,1,8;7,1,-2,2];
|
||||
b=[8,6,1,5]';
|
||||
ra=rank(a);
|
||||
rb=rank([a,b]);
|
||||
det(a);
|
||||
xx=a\b
|
||||
9
lab4/exercise4_16.m
Normal file
9
lab4/exercise4_16.m
Normal file
@@ -0,0 +1,9 @@
|
||||
t=linspace(0,4*pi,20);
|
||||
y1=sin(t);
|
||||
y2=2*cos(2*t);
|
||||
plot(t,y1,'k-');
|
||||
text(1.2,sin(1.2),'y1 \leftarrow','FontSize',12)
|
||||
hold on;
|
||||
plot(t,y2,'r--o');
|
||||
text(6,1.5,'y2 \leftarrow','FontSize',12);
|
||||
title('y1 and y2');
|
||||
6
lab4/exercise4_2.m
Normal file
6
lab4/exercise4_2.m
Normal file
@@ -0,0 +1,6 @@
|
||||
a=input('a=?');
|
||||
b=input('b=?');
|
||||
c=input('c=?');
|
||||
d=b*b-4*a*c;
|
||||
x=[(-b+sqrt(d))/(2*a),(-b-sqrt(d))/(2*a)];
|
||||
disp(['x1 =',num2str(x(1)),' ,x2=',num2str(x(2))]);
|
||||
7
lab4/exercise4_3.m
Normal file
7
lab4/exercise4_3.m
Normal file
@@ -0,0 +1,7 @@
|
||||
x=input('请输入x的值:');
|
||||
if x==10
|
||||
y=cos(x+1)+sqrt(x*x+1);
|
||||
else
|
||||
y=(3^(1/2))*sqrt(x+sqrt(x));
|
||||
end
|
||||
y
|
||||
6
lab4/exercise4_4.m
Normal file
6
lab4/exercise4_4.m
Normal file
@@ -0,0 +1,6 @@
|
||||
s=0;
|
||||
a=[12,13,14;15,16,17;18,19,20];
|
||||
for k=a
|
||||
s=s+k;
|
||||
end
|
||||
disp(s');
|
||||
9
lab4/exercise4_5.m
Normal file
9
lab4/exercise4_5.m
Normal file
@@ -0,0 +1,9 @@
|
||||
k=0;
|
||||
for n=100:200
|
||||
if rem(n,21)~=0
|
||||
k=k+1;
|
||||
continue
|
||||
end
|
||||
break;
|
||||
end
|
||||
k
|
||||
9
lab4/exercise4_7.m
Normal file
9
lab4/exercise4_7.m
Normal file
@@ -0,0 +1,9 @@
|
||||
x=-2:0.2:2;
|
||||
y=x.^2;
|
||||
plot(x,y)
|
||||
str1 = num2str(min(x));
|
||||
%数字转化为字符串
|
||||
str2 = num2str(max(x));
|
||||
%数字转化为字符串
|
||||
out = ['Value of f from ''str1'' to ''str2'' '];
|
||||
xlabel(out);
|
||||
13
lab4/exercise4_8.m
Normal file
13
lab4/exercise4_8.m
Normal file
@@ -0,0 +1,13 @@
|
||||
s1=0;s2=0;n1 =0;n2=0 ;
|
||||
x=[1,-4,-8,3,10,-9,7,-3,10, 8,-5,-2,2,0];
|
||||
m=length(x);
|
||||
for i=1:m
|
||||
if x(i)<0
|
||||
s1=s1+x(i);
|
||||
n1=n1+1;
|
||||
else
|
||||
s2=s2+x(i);
|
||||
n2=n2+1;
|
||||
end
|
||||
end
|
||||
s1,n1 ,s2,n2,m
|
||||
4
lab4/exercise4_9.m
Normal file
4
lab4/exercise4_9.m
Normal file
@@ -0,0 +1,4 @@
|
||||
A=[1,2;3,4];B=[1,2;1,4];
|
||||
C= A*B
|
||||
D= A+B
|
||||
E= A.*B
|
||||
8
lab4/f.m
Normal file
8
lab4/f.m
Normal file
@@ -0,0 +1,8 @@
|
||||
function y=f(x)
|
||||
if x<=2
|
||||
y=0.5*x;
|
||||
elseif x>6
|
||||
y=0.5;
|
||||
else
|
||||
y =1.5-0.25*x;
|
||||
end
|
||||
6
lab4/factor.m
Normal file
6
lab4/factor.m
Normal file
@@ -0,0 +1,6 @@
|
||||
function f=factor(n)
|
||||
if n<=1
|
||||
f=1;
|
||||
else
|
||||
f=factor(n-1)*n;
|
||||
end
|
||||
Reference in New Issue
Block a user