This commit is contained in:
2025-11-26 19:01:27 +08:00
parent 55b82a23bc
commit cfab7130bd
25 changed files with 3489 additions and 0 deletions

10
lab4/exercise4_1.m Normal file
View 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
View 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
View File

@@ -0,0 +1,13 @@
A=[1 2 3;4 5 6;7 8 9];
[r,c]=size(A);
% A820
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); % A820/1
A=A.*b %A820

5
lab4/exercise4_12.m Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View File

@@ -0,0 +1,6 @@
function f=factor(n)
if n<=1
f=1;
else
f=factor(n-1)*n;
end

1634
lab5/all-gps.txt Normal file

File diff suppressed because it is too large Load Diff

8
lab5/exercise5_1.m Normal file
View File

@@ -0,0 +1,8 @@
i
j
eps
inf
nan
pi
realmax
realmin

8
lab5/exercise5_7.m Normal file
View File

@@ -0,0 +1,8 @@
x=linspace(-2*pi,2*pi,21);
y=linspace(-1.5*pi,1.5*pi,31);
[xx,yy]=meshgrid(x,y);
zz=sin(xx/2).*cos(yy);
subplot(1,2,1)
surf(xx,yy,zz);axis image;
subplot(1,2,2)
contour(xx,yy,zz);axis image;

12
lab5/exercise5_8.m Normal file
View File

@@ -0,0 +1,12 @@
x=0:2:4*pi;
y=sin(x).*exp(-x/5);
xx=0:0.1:4*pi;
yya=interp1(x,y,xx,'nearest');
yyb=interp1(x,y,xx,'linear');
yyc=interp1(x,y,xx,'spline');
yyd=interp1(x,y,xx,'cubic');
yye=polyval(polyfit(x,y,6),x);
plot(xx,yya,xx,yyb,xx,yyd,x,y,'r*');
legend('nearest','linear','spline','cubic','source');
grid on
title('2007***07**.zhang')

42
lab5/lab6.m Normal file
View File

@@ -0,0 +1,42 @@
clear all;
[filename1,p1]=uigetfile('*.txt','');
fp=fopen(strcat(p1,filename1),'r');
i=1;zb=[];
while ~feof(fp)
line=fgetl(fp);
my=findstr(line,',');
zb(i).dh=line(1:my(1)-1); %
zb(i).x=str2num(line(my(1)+1:my(2)-1)); % X
zb(i).y=str2num(line(my(2)+1:my(3)-1)); % Y
zb(i).h=str2num(line(my(3)+1:my(4)-1)); % h
zb(i).dm=line(my(4)+1:end); %
i = i + 1;
end
fclose(fp);
%
a=3976223.453;
b=39512553.524;
rad=deg2rad(0.433267);
c=cos(rad);d=-sin(rad);lmd=1.000034336;
m=i-1;
gjzb=[];
for i=1:m;
gjzb(i).dh=zb(i).dh;
gjzb(i).dm=zb(i).dm;
gjzb(i).h=zb(i).h;
gjzb(i).x=a+lmd*(c*zb(1).x-d*zb(i).y);
gjzb(i).y=b+lmd*(d*zb(1).x+d*zb(i).y);
end
[filename2,p2]=uigetfile('*.txt','');
fn=fopen(strcat(p2,filename2),'w');
fprintf(fn,'%s\n\n',' X(m) Y(m) H(mm) code');
for i=1:m
fprintf(fn,'%8s',gjzb(i).dh);
fprintf(fn,'%15.3f',gjzb(i).x);
fprintf(fn,'%16.3f',gjzb(i).y);
fprintf(fn,'%10.f',gjzb(i).h);
fprintf(fn,'%8s\n',gjzb(i).dm);
end
fclose(fn);

4
lab5/plotRaram.m Normal file
View File

@@ -0,0 +1,4 @@
t=linspace(0,4*pi);
x=sin(t);
y=1-cos(t)+t/10;
plot(x,y,'-or');

11
lab5/regPolygon.m Normal file
View File

@@ -0,0 +1,11 @@
function y=regPolygon(n)
R=1;
t=0:0.01:2*pi;
x=R*cos(t);
y=R*sin(t);
m=linspace(pi/2,5/2*pi,n+1);
xz=R*cos(m);
yz=R*sin(m);
hold on
plot(x,y,xz,yz);
axis equal;

1636
lab5/result.txt Normal file

File diff suppressed because it is too large Load Diff