the last commit for lab6 exercises and a2 exercises

This commit is contained in:
2025-12-09 19:26:41 +08:00
parent cfab7130bd
commit 477d4d1668
29 changed files with 188 additions and 4 deletions

9
a2_1_1.m Normal file
View File

@@ -0,0 +1,9 @@
% 24110901003
% u=
u=3;
v=1;
%
m=(exp(u)+v)^2;
n=v^2-u;
result=m/n;
disp(result)

9
a2_1_2.m Normal file
View File

@@ -0,0 +1,9 @@
% 24110901003
% u=3v=1;
u=3;
v=1;
%
m=sqrt(u-3*v);
n=u*v;
result=m/n;
disp(result);

2
a2_3.m Normal file
View File

@@ -0,0 +1,2 @@
A=[3,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,7];
B=sprank(A)

5
a2_5.m Normal file
View File

@@ -0,0 +1,5 @@
% 24110901003
a=3;
b=a>5 % 0
a(b)=sqrt(a(b)) % 3
a(~b)=a(~b).^2 % 9

16
a2_6.m Normal file
View File

@@ -0,0 +1,16 @@
% 24110901003
% a=3,b=1,c=9;
a=3;
b=1;
c=9;
% x
syms x
%
f=a*x^2+b*x+c;
% solve
solve(f==0)
%
% ans =
%
% - (107^(1/2)*1i)/6 - 1/6
% (107^(1/2)*1i)/6 - 1/6

10
b3_5.m Normal file
View File

@@ -0,0 +1,10 @@
% c
c=3
switch (c)
case {1, 3, 5, 7, 9},
disp('The value is odd.');
case {2, 4, 6, 8, 10},
disp('The value is even.');
otherwise
disp('The value is out of range.');
end

13
b4_3.m Normal file
View File

@@ -0,0 +1,13 @@
% x,y
x=6
y=6
if (x>=0 && y>=0)
r=x+y
elseif (x>=0 && y<0)
r=x+y^2;
elseif (x<0 && y>=0)
r=x^2+y;
elseif (x<0 && y<0)
r=x^2+y^2;
end
disp(x)

View File

@@ -1,9 +1,6 @@
function jrad=deg2rad(deg)
degd=fix(deg);
degf=(deg-degd)*100;
degm=fix(degf);
degs=(degf-degm)/36.0;
jrad=(degd+degm/60.00+degs)* pi / 180.0;
jrad=(degd+degm/60.00+degs)* pi / 180.0;

View File

4
lab6/exercise6_1.m Normal file
View File

@@ -0,0 +1,4 @@
A=[0,9,6;1,3,0];
B=[1,4,3;1,5,0];
A&B
A./B

3
lab6/exercise6_10.m Normal file
View File

@@ -0,0 +1,3 @@
syms x;
eq1=x^4-4*x^3+12*x-9==0;
x=solve(eq1,x)

8
lab6/exercise6_8.m Normal file
View File

@@ -0,0 +1,8 @@
for k=1:10
if k>6
break
else
arry(k)=k;
end
end
disp(arry);

7
lab6/exercise6_9.m Normal file
View File

@@ -0,0 +1,7 @@
i=2;
a=2i;
b=2*i;
c=2*sqrt(-1);
a
b
c

4
lab6/exercise6_c_1.m Normal file
View File

@@ -0,0 +1,4 @@
A=[1,2,3;4:6;7:9];
C=[A;[10,11,12]];
D=C(1:3,[2,3]);
E=C(2,[1,2]);

9
lab6/exercise6_c_2.m Normal file
View File

@@ -0,0 +1,9 @@
x=[0,1,0,2,0,3,0,4];
for k=1:8
if x(k)==0
x(k)=k;
else
x(k)=2*k+1;
end
end
disp(x)

3
lab6/exercise6_c_3.m Normal file
View File

@@ -0,0 +1,3 @@
syms a b c x;
s=a*x^2+b*x+c;
solve(s)

3
lab6/exercise6_c_4.m Normal file
View File

@@ -0,0 +1,3 @@
A=[2,3,1,2;1,3,0,1;1,-1,1,8;7,1,-2,2];
B=[8,6,1,5];
A\B'

7
lab6/exercise6_c_5.m Normal file
View File

@@ -0,0 +1,7 @@
t=linspace(0,2*pi,50);
y1=sin(2.*t-0.3);
y2=3.*cos(t+0.5);
plot(t,y1,'-.ro');
hold on
plot(t,y2,':b*');
hold off

8
lab6/exercise6_d.m Normal file
View File

@@ -0,0 +1,8 @@
for i=100:999
a=fix(i/100); %
b=rem(fix(i/10),10); %
c=rem(i,10); %
if a^3+b^3+c^3==i
disp(i);
end
end

11
lab6/lab6.m Normal file
View File

@@ -0,0 +1,11 @@
[F,P]=uigetfile('*.pgm;*.jpg;*.jpeg;*.tif;*.tiff;*.bmp;*.png;*.hdf;*.pcx;*.xwd','');
imna=strcat(P,F);
myi=imread(imna);
figure(1);
imshow(myi);
figure(2);
image(myi);
bgray=rgb2gray(myi);
figure(3);
imshow(bgray);
imwrite(bgray,'th.bmp','bmp');

BIN
lab6/th.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

3
untitled.m Normal file
View File

@@ -0,0 +1,3 @@
A=ones(5,4);
size(A)
zeros(size(A))

4
untitled12.m Normal file
View File

@@ -0,0 +1,4 @@
A=[4,5];
B=[9,3];
%
distance=(A(1,1)-B(1,1))^2+(A(1,2)-B(1,2)^2)

9
untitled13.m Normal file
View File

@@ -0,0 +1,9 @@
% 24110901003
% u=3v=1;
u=3;
v=1;
%
m=sqrt(u-3*v);
n=u*v;
result=m/n;
disp(result);

19
untitled4.m Normal file
View File

@@ -0,0 +1,19 @@
%
A=[-2.0,5.0,1.0,3.0,4.0,-1.0;...
2.0,-1.0,-5.0,-2.0,6.0,4.0;...
-1.0,6.0,-4.0,-5.0,3.0,-1.0;...
4.0,3.0,-6.0,-5.0,-2.0,-2.0;...
-3.0,6.0,4.0,2.0,-6.0,4.0;...
2.0,4.0,4.0,4.0,5.0,-4.0];
B=[0.0;1.0;-6.0;10.0;-6.0;-2.0];
%
A\B
%
% ans =
%
% 0.6626
% -0.1326
% -3.0137
% 2.8355
% -1.0852
% -0.8360

16
untitled6.m Normal file
View File

@@ -0,0 +1,16 @@
% a3
a=3;
A=randn(a)
%
det(A)
% A =
%
% 0.7172 1.0347 0.2939
% 1.6302 0.7269 -0.7873
% 0.4889 -0.3034 0.8884
%
%
% ans =
%
% -1.8548

0
untitled9.m Normal file
View File

5
四、2.m Normal file
View File

@@ -0,0 +1,5 @@
% A\B
A=[4,5];
B=[9,3];
%
distance=(A(1,1)-B(1,1))^2+(A(1,2)-B(1,2)^2)