Initial commit

This commit is contained in:
2025-10-10 17:29:33 +08:00
Unverified
commit 49047b316d
47 changed files with 323 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
shu=[];
for m=100:999
m1=fix(m/100);
m2=rem(fix(m/10),10);
m3=rem(m,10);
if m == m1^3 + m2^3 + m3^3
shu=[shu,m];
end
end
disp(shu)
+6
View File
@@ -0,0 +1,6 @@
y = 0;
n = 100;
for i=1:n
y=y+1/(i*i);
end
y
+14
View File
@@ -0,0 +1,14 @@
a = 0;
b = 3 * pi;
n = 1000;
h = (b-a)/n;
x=a;
s=0;
f0=exp(-0.5*x)*sin(x+pi/6);
for i=1:n
x=x+h;
f1=exp(-0.5*x)*sin(x+pi/6);
s=s+(f0+f1)*h/2;
f0=f1;
end
s
+6
View File
@@ -0,0 +1,6 @@
x=(0:pi/100:2*pi);
y1=2*exp(-0.5*x);
y2=2*exp(-0.5*x).*sin(2*pi*x);
x1=(0:12)/2;
y3=2*exp(-0.5*x1).*sin(2*pi*x1);
plot(x,y1,'k:',x,y2,'b--',x1,y3,'rp');
+10
View File
@@ -0,0 +1,10 @@
x=(0:pi/100:2*pi)';
y1=2*exp(-0.5*x)*[1,-1];
y2=2*exp(-0.5*x).*sin(2*pi*x);
plot(x,y1,'b:');
axis([0,2*pi,-2,2]);
hold on;
plot(x,y2,'k');
legend('线','线','线y');
hold off;
grid on;
+4
View File
@@ -0,0 +1,4 @@
x=linspace(0,2*pi,60);
y=sin(x);
z=cos(x);
t = sin(x) ./ (cos(x)+eps);
+10
View File
@@ -0,0 +1,10 @@
x=0:0.1:100;
y=10*x.*x;
subplot(2,2,1);plot(x,y);
title('plot(x,y)');grid on;
subplot(2,2,2);semilogx(x,y);
title('semilogx(x,y)');grid on;
subplot(2,2,3);semilogy(x,y);
title('semilogy(x,y)');grid on;
subplot(2,2,4);loglog(x,y);
title('loglog(x,y)');grid on;
+22
View File
@@ -0,0 +1,22 @@
x=linspace(0,10,100);
y=[];
for x0=x
if x0>=8
y=[y,1];
elseif x0>=6
y=[y,5-x0/2];
elseif x0>=4
y=[y,2];
elseif x0>=0
y=[y,sqrt(x0)];
end
end
plot(x,y);
axis([0,10,0,2.5]);
title('线');
xlabel('Variable X');
ylabel('Variable Y');
text(2,1.3,'y=x^{1/2}');
text(4.5,1.9,'y=2');
text(7.3,1.5,'t=5-x/2');
text(8.5,0.9,'y=1');
+11
View File
@@ -0,0 +1,11 @@
clear;
load ctr.mat A
X = A(:,1);
[xed,xh]=sort(X);
[m,n]=size(A);
C = [];
for i = 1 : m
B = A(xh(m-i+1),1:n);
C = [C;B];
end
num2str([(1 : m)' C])
BIN
View File
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
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;
+3
View File
@@ -0,0 +1,3 @@
N = [5.2,2.4,0,-1.7;2.4,7.4,2.3,2.7;0,2.3,6.3,0;-1.7,2.7,0,4.4];
D = det(N)
DJ = diag(N)'
+3
View File
@@ -0,0 +1,3 @@
D = diag([1,2,3;4,5,6;7,8,9]);
disp(D)
diag([1,1,1,2,2,2])
+2
View File
@@ -0,0 +1,2 @@
a=[1,2,3;4,5,6;7,8,9]
a=a([2,2],:)
+4
View File
@@ -0,0 +1,4 @@
clear
a=eye(3,3)
b=[7 8 9]
a(3,:)=b([3 1 2])
+6
View File
@@ -0,0 +1,6 @@
clear;
a=1:10;
b=[11,12,13,14;15,16,17,18];
c=a;a=b;b=c;
a
b
+4
View File
@@ -0,0 +1,4 @@
function foo(x,y)
if nargin ~= 2
error('Warning number of input argument')
end
+7
View File
@@ -0,0 +1,7 @@
function grid=gridbearing(a,b)
grid = a + b ;
if grid > 360
grid -= 360;
elseif grid < 0
grid += 360;
end
+15
View File
@@ -0,0 +1,15 @@
% x=input('please type a number \n');
% if fix(x) == x
% disp(x);
% end
a = input('a=?');
b = input('b=?');
c = input('c=?');
d = b * b - 4 * a * c ;
if d > 0
x = [(-b + sqrt(d))/(2 * a),(-b - sqrt(d))/(2 * a)];
disp(['x1=',num2str(x(1)),'x2=',num2str(x(2))]);
else
disp(' ');
end
+10
View File
@@ -0,0 +1,10 @@
c = input ('','s');
if c >= 'A' && c <= 'Z'
disp(lower(c));
elseif c >= 'a' && c <= 'z'
disp(upper(c));
elseif c >='0' && c <='9'
disp(str2double(c)^2);
else
disp(c);
end
+9
View File
@@ -0,0 +1,9 @@
N = [5.2,2.4,0,-1.7;2.4,7.4,2.3,2.7;0,2.3,6.3,0;-1.7,2.7,0,4.4];
W = -[7;8;6;-3];
K = (inv(N)*W)';
disp(K);
N * inv(N)
[V,D]= eig(N)
abs(N*V-V*D)
b = mean(N)
c = std(N)
+10
View File
@@ -0,0 +1,10 @@
filename = 'leika.txt';
fp = fopen(filename,"r");
i = 0;
while ~feof(fp)
i = i + 1;
for j = 1 : 4
zb(i,j)=fscanf(fp,'%f',1);
end
end
fclose(fp);
+9
View File
@@ -0,0 +1,9 @@
filename = 'leika.txt';
fp = fopen(filename,"r");
i = 0;
zb=[];
while ~feof(fp)
line = fgetl(fp)
my = sscanf(line,'%g')
end
fclose(fp);
+4
View File
@@ -0,0 +1,4 @@
filename='leika.txt';
fp = fopen(filename,"r");
zb = fscanf(fp,'%f');
fclose(fp);
+6
View File
@@ -0,0 +1,6 @@
20 50122.563 79997.730 401.113
21 50122.794 80011.106 401.085
22 50004.381 80007.744 399.831
23 50119.260 79997.344 401.181
24 50006.659 80024.175 399.504
25 50105.337 79995.006 400.849
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
fid = fopen('magic5.dat','w');
cnt = fwrite(fid,magic(5),"int32");
fclose(fid);
+14
View File
@@ -0,0 +1,14 @@
filename1='nikon.txt';
fp=fopen(filename1,'r');
i=1;zb=[];
while ~feof(fp)
line=fgetl(fp);
my=strfind(line,',');
zb(i).dh=line(1:my(1)-1);
zb(i).x=str2num(line(my(1)+1:my(2)-1));
zb(i).y=str2num(line(my(2)+1:my(3)-1));
zb(i).h=str2num(line(my(3)+1:my(4)-1));
zb(i).dm=line(my(4)+1:end);
i=i+1;
end
fclose(fp);
+7
View File
@@ -0,0 +1,7 @@
3,49510.3110,80362.3190,405.8240,s50
63,49488.9080,80426.0080,408.8490,S77
164,49461.2960,80462.3610,408.9950,S77
165,49457.2500,80485.8770,409.4490,S81
166,49476.6650,80395.8870,408.1090,S66
167,49475.1380,80398.7300,408.1570,S77
298,49465.2360,80593.9700,415.1290,S99
+2
View File
@@ -0,0 +1,2 @@
y=peaks;
plot(y);
+3
View File
@@ -0,0 +1,3 @@
x = (1:1:20);
y = x / 3;
plot(x,y)
+3
View File
@@ -0,0 +1,3 @@
x = linspace(0,2 * pi);
y = sin(x);
plot(x,y);
+3
View File
@@ -0,0 +1,3 @@
x=linspace(0,2*pi,100);
y=[sin(x);cos(x)];
plot(x,y);
+2
View File
@@ -0,0 +1,2 @@
x=linspace(0,2*pi,100);
plot(x,sin(x),'.',x,cos(x),'<', x,cos(x)+sin(x),'>');
+4
View File
@@ -0,0 +1,4 @@
x = linspace(0,2*pi);
y1=sin(x);
y2=exp(-x);
plotyy(x,y1,x,y2);
+3
View File
@@ -0,0 +1,3 @@
x=0:0.5:4*pi;
y=sin(x);
plot(x,y,'b->')
+4
View File
@@ -0,0 +1,4 @@
x=0:0.1:4*pi;
y=sin(x);
plot(x,y);
axis([-inf,inf,0,1]);
+15
View File
@@ -0,0 +1,15 @@
price=input('');
switch fix(price/100)
case {0,1}
rate = 0;
case {2,3,4}
rate=3/100;
case num2cell(5:9)
rate=5/100;
case num2cell(10:24)
rate=8/100;
rate=10/100;
otherwise
rate=14/100;
end
price=price*(1-rate)
+9
View File
@@ -0,0 +1,9 @@
clear;
rad=5.43813680292244;
rad=rem(rad,2*pi)*180/pi;
deg=fix(rad);
xsbf=(rad-deg)*60;
degf=fix(xsbf);
degm=(xsbf-degf)*60;
jdeg=deg+degf/100.0+degm/10000.0;
disp(jdeg);
+7
View File
@@ -0,0 +1,7 @@
function jdeg=rtod(rad)
rad=rad*180/pi;
deg=fix(rad);
xsbf=(rad-deg)*60;
degf=fix(xsbf);
degm=(xsbf-degf)*60;
jdeg=deg+degf/100.0+degm/10000.0;
+18
View File
@@ -0,0 +1,18 @@
% str1 = 'I like matlab,';
% str2 = 'JavaScript, and Perl!';
% str3 = [str1 str2];
% disp(str3)
% ansi编码
% str1 = 'abcdefgh';
% str2 = upper(str1);
% str3 = lower(str2);
% double(str1)
% double(str2)
%
str1 = 'today';
str2 = 'tomorrow';
str3 = 'today';
out1 = strcmp(str1,str2)
out2 = strcmp(str1,str3)
+2
View File
@@ -0,0 +1,2 @@
b = '23,T02,78354.344,89342.333,437.557,0203';
w = findstr(',',b)
+11
View File
@@ -0,0 +1,11 @@
total.name='23';
total.x=78354.344;
total.y=89342.333;
total.h=437.557;
total.code='0203';
total(2) = struct('name','23','xyh',[78354.344,89342.233,437.557],'code','0203')
total(1).x=76434.455;
disp(total)
total(1)=[]
rmfield(total(1),'code')
+9
View File
@@ -0,0 +1,9 @@
n=1;s=1;
while s <= 10000
n = n + 1;s = s + n;
end
if s - 10000 > abs(s - n - 10000)
[n-1 s-n]
else
[n s]
end
+3
View File
@@ -0,0 +1,3 @@
function [rho,theta]=tran(x,y)
rho = sqrt(x^2 + y^2);
theta=atan(y/x);
+7
View File
@@ -0,0 +1,7 @@
A = input('A');
B = input('B');
try
C = A * B
catch
lasterr
end