说 明
1、 计算机应用实践是本科教学重要的实践教学环节,是提高学生应用计算机能力的重要措施。所有参加计算机应用实践教学活动的学生都必须撰写实践报告
2、 计算机应用实践报告的质量反映了计算机应用实践的教学质量,它是评定计算机应用实践成绩的主要依据之一。不交实践报告者不得参加实习成绩评定。
3、 指导教师必须对学生的实践报告写出评语并在相应位置给出成绩并签字,否则本实践报告无效。
4、 实践报告要求条理清晰,内容详尽,数据准确,字数不少于5000字。
5、 计算机应用实践活动结束后请将本报告上交学院存档保存。
计算机应用实践报告
第一天:
1、 随机矩阵的生成,及求解矩阵的逆、矩阵的秩、矩阵的转置。
命令如下:
clear all;clc
a=[binornd(10,0.5,8,8)] %生成随机的二项分布矩阵。
a1=[rand(10,10)] %在0~1之间随机生成矩阵
b=a'
%求矩阵的转置
c=a^-1
%求矩阵的逆
d=rank(a)
%求矩阵的秩。
结果如下:
a =
3 6 7 6 3 6 4 2
8 3 4 3 7 4 5 4
4 4 6 6 4 7 5 9
4 5 5 7 3 3 2 4
7 7 4 5 5 5 7 3
7 3 3 1 4 6 5 5
5 9 5 8 5 4 3 5
5 2 7 3 4 4 3 5
a1 =
Columns 1 through 4
0.575726948453721 0.375091630987986 0.897771225532002 0.652915682156136
0.842344701828773 0.828893745056770 0.497230128936991 0.381489065282516
0.499725973621345 0.841776581954761 0.771303428858631 0.300018582740438
0.439024887659214 0.665238451557799 0.060362229423969 0.340139555506767
0.149057083245688 0.960139975886254 0.262457464904029 0.918926536712417
0.028279450895793 0.943117892210703 0.651069368702479 0.456266813303239
0.756669787984348 0.112699492380728 0.133603910449774 0.442496952598123
0.796106235942840 0.648287449225586 0.638545736824786 0.454185819615522
0.293555594417440 0.480804051679440 0.384943094967874 0.945282009186640
0.115206746018031 0.066520691949122 0.765698125674700 0.219118952550175
Columns 5 through 8
0.882402795931734 0.649417450961366 0.125324791415593 0.751157321899609
0.019875422824709 0.342720632582221 0.364477175202600 0.419379649992969
0.341764883237310 0.493299255574885 0.676230090282253 0.000231065199417
0.766027445694415 0.701773945253530 0.375758171217492 0.149463732367703
0.342803701519393 0.887802601429490 0.863458491467109 0.273834301544268
0.618806404154405 0.055057846156185 0.291976750986029 0.872425018962880
0.453021162091896 0.098361950545730 0.133474990584297 0.601251143911812
0.010162602627914 0.649782785472762 0.672650514427429 0.321188452831265
0.599081167470487 0.764070891236327 0.202584980871927 0.284293074456312
0.601568348358472 0.987958941597840 0.868515198201092 0.435315805784207
Columns 9 through 10
0.903759051181981 0.022627986755907
0.925105644987009 0.065074042464646
0.505292452205831 0.923956335725144
0.627581809270030 0.534142863944270
0.719263926822410 0.366796468997375
0.023912881359655 0.363946179540744
0.574932501996900 0.151373665826451
0.046534464064038 0.149608598632666
0.422531388268483 0.350802091637144
0.467734261291993 0.335966095668561
b =
3 8 4 4 7 7 5 5
6 3 4 5 7 3 9 2
7 4 6 5 4 3 5 7
6 3 6 7 5 1 8 3
3 7 4 3 5 4 5 4
6 4 7 3 5 6 4 4
4 5 5 2 7 5 3 3
2 4 9 4 3 5 5 5
c =
Columns 1 through 4
-0.088937688718089 -0.070726097286246 -0.175707781574489 0.349484604390092
-0.045566840516058 -0.178424375514686 -0.075761734833928 -0.237716167993412
0.007960472138348 -0.117977793974273 -0.066116406523612 -0.087262298030233
0.042821850123525 0.131115885921985 0.062888676441357 0.361742406315371
0.120779577271480 0.357435611044327 0.083655948583490 -0.319223451683436
0.275322536371123 0.131248402699556 0.015305687809403 0.053271744583377
-0.104858632994785 -0.076149819682528 0.128938824576183 -0.096680454721857
-0.183639857260500 -0.116662091682679 0.104309634916278 -0.078506725226462
Columns 5 through 8
0.007600783742084 0.231450017511146 -0.118858083996706 0.011689872878548
0.071369750205874 0.047488333790832 0.266264068075762 0.130936041723854
0.074777324486261 -0.082870313402179 0.013724951962668 0.304296383238521
-0.031756699196380 -0.062907607409581 -0.202031292890475 -0.240622071615853
-0.191250106486696 -0.183620926292275 0.173757891847379 -0.104849167510672
-0.300775223148788 0.239656592236410 -0.042547351084271 -0.301939477694587
0.375287514079908 -0.223499010856910 -0.146307987922042 0.092752278815300
0.046664836673072 -0.007411474059841 0.097172659895690 0.124073565742520
d =
8
2、 矩阵的输入,并计算已知矩阵的乘积,并求逆。
命令:
clear all;clc
A=[2 7 9 6 1 0;3 5 0 7 8 7 ;5 5 1 0 2 1 ;
1 4 7 4 2 0 ;6 0 5 3 2 0 ] %输入矩阵
B=[1 7 0 1 3 6 0 ;3 8 4 5 3 4 5 ;2 6 5 2 1 8 4;2 5 5 4 4 5 2 ;
5 1 9 6 8 3 1;7 1 6 0 7 2 9 ]
C=A*B
%求矩阵A B的乘积。
d=rank(C)
%求矩阵A B的乘积的秩。
e=rank(A)
f=rank(B)
结果:
A =
2 7 9 6 1 0
3 5 0 7 8 7
5 5 1 0 2 1
1 4 7 4 2 0
6 0 5 3 2 0
B =
1 7 0 1 3 6 0
3 8 4 5 3 4 5
2 6 5 2 1 8 4
2 5 5 4 4 5 2
5 1 9 6 8 3 1
7 1 6 0 7 2 9
C =
58 155 112 85 68 145 84
121 111 169 104 165 111 110
39 84 49 44 54 66 40
45 103 89 63 54 104 58
32 89 58 40 51 97 28
d =
5
e =
5
f =
6
第二天:
1. 顺序:先四则运算,再关系运算,最后逻辑运算。
2、常用的字符串函数,运用格式及结果。
命令
str='a+b, c+d,e+f ';
str2='x,y ,Z';
x='z=1';
y='123';
a=strcmp(str,str2) %比较两个字符串是否相等
b=strncmp(str,str2,2) %比较两个字符串的前n项是否相等
c=findstr(str,'+') %查找字符串
d=strmatch('a',strvcat(str,str2)) %查找所在行数
e=strtok(str2) %查找第一个分隔符
f=upper(str) %小写换大写
g=lower(str2) %大写换小写
h=strrep(str,'a+b','1+2') %改变部分字符
i=strjust(str,'left') %对齐字符串
eval(x) %执行字符串中的
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
达式
j=blanks(5) %空字符串
deblank(str) %删除字符串后面的空格
str2mat(x,y) %字符串形成文本
运行结果
Str=
a+b, c+d,e+f
str2 =
x,y ,Z
x =
z=1
y =
123
a =
0
b =
0
c =
2 7 11
d =
1
e =
x,y
f =
A+B, C+D,E+F
g =
x,y ,z
h =
1+2, c+d,e+f
i =
a+b, c+d,e+f
z =
1
j =
ans =
a+b, c+d,e+f
ans =
z=1
123
3、课后习题:
(1)用不同的格式显示自然底数e的值
a=exp(1)
a =
2.718281828459046
format long,a
a =
2.718281828459046
format short e,a
a =
2.7183e+000
format long e,a
a =
2.718281828459046e+000
format rat,a
a =
1457/536
format hex,a
a =
4005bf0a8b14576a
(2)计算矩阵间的点乘与乘。
>> A=[1 2 3;4 5 6;7 8 9];
>> B=[4 6 8;5 5 6;3 2 2];
>> A*B
ans =
23 22 26
59 61 74
95 100 122
A.*B
ans =
4 12 24
20 25 36
21 16 18
3、对矩阵做简单的逻辑运算,以及关系运算。
>> A=[5 2;9 1];
>> B=[1 2;9 2];
>> A>B
ans =
1 0
0 0
>> A==B
ans =
0 1
1 0
>> A
> (A==B)&(A> (A==B)&(A>B)
ans =
0 0
0 0
4、编写一个程序,比较两个字符串,如果s1>s2,输出1; 如果s1s2
n=1
elseif s1> lx_4(345,456)
n =
0
ans =
0
第三天:
1、创建矩阵:
>> A=[1 0 0;0 2 -1;0 -1 3]
A =
1 0 0
0 2 -1
0 -1 3
>> B=[3 5 7;0 1 0]
B =
3 5 7
0 1 0
>> C=[1 1;1 1;1 1]
C =
1 1
1 1
1 1
>> D=[0 0 0;0 0 0;]
D =
0 0 0
0 0 0
10、对已知矩阵,做相应的加减、左右乘运算,并分别求行列式。
>> A=[1 3;3 5];
>> B=[2 4;6 8];
>> A+B
ans =
3 7
9 13
>> A-B
ans =
-1 -1
-3 -3
>> A*B
ans =
20 28
36 52
>> B*A
ans =
14 26
30 58
>> det(A)
ans =
-4
>> det(B)
ans =
-8
11、对已知矩阵求行列式,逆,矩阵的幂,以及行最简形。
>> A=[1 3 5;0 2 7;-1 1 3];
>> det(A)
ans =
-12
>> inv(A)
ans =
0.0833 0.3333 -0.9167
0.5833 -0.6667 0.5833
-0.1667 0.3333 -0.1667
>> A*A*A
ans =
-45 57 201
-42 36 147
-15 3 27
A'*A
ans =
2 2 2
2 14 32
2 32 83
>> rref(A)
ans =
1 0 0
0 1 0
0 0 1
13、计算已知数组的点乘,点除,点幂。
>> a=[3 0 -1 4];
>> b=[-2 1 4 7];
>> a.*b
ans =
-6 0 -4 28
>> a.^2
ans =
9 0 1 16
>> a./b
ans =
-1.5000 0 -0.2500 0.5714
>> a*b'
ans =
18
>> a'*b
ans =
-6 3 12 21
0 0 0 0
2 -1 -4 -7
-8 4 16 28
14、求矩阵的特征行列式,以及全部的特征值组成的列向量
>> A=[2 1 1;1 2 1;1 1 2];
>> poly(A)
ans =
1.0000 -6.0000 9.0000 -4.0000
>> [V,D]=eig(A)
V =
0.4082 0.7071 0.5774
0.4082 -0.7071 0.5774
-0.8165 0 0.5774
D =
1.0000 0 0
0 1.0000 0
0 0 4.0000
15、
>> A=[3 0;1 9];
>> poly(A)
ans =
1 -12 27
>> [V,D]=eig(A)
V =
0 0.9864
1.0000 -0.1644
D =
9 0
0 3
20、
(2)
>> A=[2 -1 3 0;1 4 -2 1;5 3 2 1;2 3 1 -1];
B=[13;-8;10;-6];
X=A\B
X =
1.0000
-2.0000
3.0000
21、
(1)、>> A=[1 1 2 -1;-1 1 3 0;2 -3 4 -1];
>> rref(A)
ans =
1.0000 0 0 -0.5600
0 1.0000 0 -0.2000
0 0 1.0000 -0.1200
X=[0.56,0.2,0.12,1]
(2).
>> A=[1 -1 -1 1 0;1 -1 1 -3 1;1 -1 -2 3 -0.5];
>> rref(A)
ans =
1.0000 -1.0000 0 -1.0000 0.5000
0 0 1.0000 -2.0000 0.5000
0 0 0 0 0
得到一个特解:c=(0.5,0,0.5,0)
在求解对应的其次线性方程组
,可得到一个基础解系:
a=[1 1 0 0],b=[1 0 2 1].
所以它的通解是:
X=t1*a+t2*b+t3*c.
第四天:
1、利用例题所给的公式求π的近似值,直到某一项的绝对值小于10^(-6).
clear all;clc
i=1;m=0;
while 1/i>=10^(-6);
m=m+(-1)^((i-1)/2)*(1/i);
i=i+2;
end
4*m
结果:
ans =
3.141590653589692
2、编写一个程序,考试成绩在[90,100]的显示优秀,成绩在[80,90)的显示良好,成绩在[60,80)的显示及格,成绩在[0,60)的显示不及格。
function y=lx3_2(x)
if x<60
disp('不及格')
elseif x<80
disp('及格')
elseif x<90
disp('良好')
else disp('优秀')
end
end
结果:
>> lx3_2(34)
不及格
>> lx3_2(78)
及格
>> lx3_2(85)
良好
>> lx3_2(97)
优秀
3、利用for循环找出100~200之间的的所有素数。
clear all; clc
i=1;n=0;
for i=1:50
n=n+prod(1:i);
end
n
结果:
n =
3.103505322954620e+064
4、求斐波那契数列的前40个数。
clear all;clc
a=[];
for i=100:200
for j=2:i-1
if 0==rem(i,j)
break
end
end
if i-1==j
a=[a,i];
end
end
a
结果:
a =
Columns 1 through 11
101 103 107 109 113 127 131 137 139 149 151
Columns 12 through 21
157 163 167 173 179 181 191 193 197 199
5、
clear all;clc
A(1,1)=1;A(1,2)=1;B=[1,1];
for i=3:40
j=i-1;
k=i-2;
A(1,i)=A(1,j)+A(1,k);
a=A(1,i);
B=[B,a];
end
B
结果:
B =
Columns 1 through 5
1 1 2 3 5
Columns 6 through 10
8 13 21 34 55
Columns 11 through 15
89 144 233 377 610
Columns 16 through 20
987 1597 2584 4181 6765
Columns 21 through 25
10946 17711 28657 46368 75025
Columns 26 through 30
121393 196418 317811 514229 832040
Columns 31 through 35
1346269 2178309 3524578 5702887 9227465
Columns 36 through 40
14930352 24157817 39088169 63245986 102334155
例题&练习:
6、
clear all;clc
n=1;m=1;
while prod(1:n)<1e10
n=n+1;
end
n
while prod(1:m)<2^10
m=m+1;
end
m
结果:
n =
14
m =
7
7、求和
clear all;clc
i=1;sum=0;
while i<=10
sum=sum+i;
i=i+1;
end
sum
结果:
Sum=
55
8、
clear all;clc
n=1;i=1;
while n<1000
n=n+1;
i=i+1/n^2;
end
i
结果:
i =
1.643934566681562
9、
clear all;clc;
input_num=input('enter the number:')
switch input_num
case -1
disp('negative one');
case 0
disp('zero');
case 1
disp('positive');
otherwise disp('other value');
end
结果:
enter the number:1
input_num =
1
positive
10、
clear all;clc
A=binornd(10,0.4,4,5);B=[];
disp(A(1,1))
b=size(A);
for i=1:b(1)
for j=1:b(2)
B=[B,A(i,j)];
end
end
B
结果:
4
B =
Columns 1 through 11
4 5 6 2 4 3 3 4 4 5 7
Columns 12 through 20
5 3 9 5 4 2 5 5 5
第五天:
1、
clear all;clf
x=0:pi/50:4*pi;
y1=exp(x/3).*sin(3*x)
plot(x,y1,'b*')
hold on
x=0:pi/50:4*pi;
y2=-exp(x/3);y3=exp(x/3)
plot(x,y2,'r-.',x,y3,'r-.')
结果:
2、fplot('exp(-2*t/3)*sin(1+2*t)',[1,10])
结果1:
ezplot('exp(-2*t/3)*sin(1+2*t)',[1,10])
结果2
3、
clear all;clf
x1=-pi:pi/50:pi;
x2=pi:pi/50:4*pi;
x3=1:.1:8
y1=x1.*cos(x1);
y2=x2.*tan(1./x2).*sin(x2.^3);
y3=exp(1./x3).*sin(x3);
subplot(1,3,1),plot(x1,y1,'rh')
xlabel('x轴') ,ylabel('y轴')
legend('y1=x1.*cos(x1)') %legend
gtext('y1=x1.*cos(x1)') %gtext
axis([-4,4,-4,4]) %axis
title('曲线y1=x1.*cos(x1)') %title
subplot(1,3,2),plot(x2,y2,'g')
xlabel('x轴') ,ylabel('y轴') %xlabel & ylabel
legend('y2=x2.*tan(1./x2).*sin(x2.^3)')
gtext('y2=x2.*tan(1./x2).*sin(x2.^3)')
title('曲线y2=x2.*tan(1./x2).*sin(x2.^3')
subplot(1,3,3),plot(x3,y3,'cs')
xlabel('x轴') ,ylabel('y轴')
title('曲线y3=exp(1./x3).*sin(x3)')
legend('y3=exp(1./x3).*sin(x3)')
gtext('y3=exp(1./x3).*sin(x3)')
结果:
4、
clear all;clf;clc
x=1:.1:10;
y=exp(x.^2)
semilogy(x,y)
结果:
5、
clear all;clc;clf
t=0:pi/50:20*pi
x=t.*cos(pi./6*t)
y=t.*sin(pi./6*t)
z=2*t
plot3(x,y,z,'go')
title('圆锥螺线')
text(0,0,0,'(0,0,0)')
xlabel('x轴'),ylabel('y轴'),zlabel('z轴')
colordef white
grid on
结果:
第六天:
1、
function fx=fun01(m,k)
n=1;A=[];
while n<=k;
m=m+1;
for j=2:m-1
if 0==rem(m,j)
break
end
end
if m-1==j
disp(m);
A=[A,m];
n=n+1;
end
end
end
结果:
>> fun01(17,5)
19
23
29
31
37
2、
load in02.dat
B=[in02];n=size(B);b=[];
for i=1:n(1);
for j=(1:n(2));
a1=rem(B(i,j),10);a2=fix(B(i,j)/10);a3=fix(B(i,j)/100);a4=fix(B(i,j)/1000);
if rem(a1,2)==0&rem(a2,2)==0&rem(a3,2)==0&rem(a4,2)==0;
b=[b,B(i,j)];
end
end
end
a=sort(b);
fliplr(a)
cnt=length(b)
结果:
ans =
Columns 1 through 7
8880 8880 8822 8822 8682 8682 8682
Columns 8 through 14
8682 8682 8682 8682 8682 8400 8400
Columns 15 through 21
8240 8240 8240 8240 8240 8240 8240
Columns 22 through 28
8240 8044 8044 6468 6468 6468 6468
Columns 29 through 35
6468 6468 6468 6468 6408 6408 6408
Columns 36 through 42
6408 6408 6408 6408 6408 6002 6002
Columns 43 through 49
6002 6002 6002 6002 6002 6002 4820
Columns 50 through 56
4820 4686 4686 4448 4448 4448 4448
Columns 57 through 63
4448 4448 4448 4448 4068 4068 4068
Columns 64 through 70
4068 4068 4068 4068 4068 4068 4068
Columns 71 through 77
4068 4068 4068 4068 4068 4068 400
Columns 78 through 84
4006 4006 4006 4006 4006 4006 4006
Columns 85 through 91
2840 2840 2468 2468 2468 2468 2468
Columns 92 through 98
2468 2468 2468 2406 2406 2406 2406
Columns 99 through 104
2406 2406 2406 2406 2222 2222
cnt =
104
3、
load in03.dat;
A=[in03];n=size(A);m=n(1)*n(2);b=[];
for i=1:m-5
if rem(A(i),2)==1&A(i)>A(i+1)&A(i)>A(i+2)&A(i)>A(i+3)&A(i)>A(i+4)&A(i)>A(i+5);
b=[b,A(i)];
end
end
b=sort(b)
cnt=length(c)
结果:
b =
Columns 1 through 6
5035 6667 7001 8047 8683 8823
Columns 7 through 9
8881 8889 8949
cnt =
9
4、
function fx=fun04(t1,t2)
a(1)=1;a(2)=1;b=[];
for i=1:t2
a(i+2)=a(i+1)+a(i);
if a(i)>=t1&a(i)<=t2;
b=[b,a(i)];
end
end
fx=b;
结果:
fun04(1,9990)
ans =
Columns 1 through 6
1 1 2 3 5 8
Columns 7 through 12
13 21 34 55 89 144
Columns 13 through 18
233 377 610 987 1597 2584
Columns 19 through 20
4181 6765
5
x1=0;x0=0;x1=cos(x0);
while abs(x0-x1)>=0.000001;
x0=x1;
x1=cos(x0);
end
x1
、
结果:
x1 =
0.739085526361924
6、
load in06.dat;
A=[in06];n=size(A);m=n(1)*n(2);sumint=0;sumdec=0;
aver=mean(A);
for i=1:m;
sumint=sumint+fix(A(i));
sumdec=sumdec+(A(i)-fix(A(i)));
end
sumint
sumdec
结果:
sumint =
144620
sumdec =
75.355200000000423
7、b=[];
for a=100:999;
a1=rem(a,10);a2=rem(fix(a/10),10);a3=fix(a/100);
for c=10:32;
if sqrt(a)==c&(a1==a2|a1==a3|a2==a3)
b=[b,a];
end
end
end
b=sort(b)
结果:
b =
100 121 144 225 400 441 484 676 900
8、
A=[];
for a=11:999
b=floor(log10(a))+1;
v=mod(floor(a./10.^(b-1:-1:0)),10);
w=fliplr(v);
if v==w
A=[A,a];
end
end
B=[];
for i=1:length(A)
a1=A(i);a2=a1.^2;
b=floor(log10(a2))+1;
v=mod(floor(a2./10.^(b-1:-1:0)),10);
w=fliplr(v);
if v==w
B=[B,a1];
end
end
C=[];
for i=1:length(B)
a3=B(i);a4=a3.^3;
b=floor(log10(a4))+1;
v=mod(floor(a4./10.^(b-1:-1:0)),10);
w=fliplr(v);
if v==w
C=[C,a3];
end
end
C
结果:
C =
11 101 111
9、
load in09.dat
B=[in09];n=size(B);b=[];m=n(1)*n(2);
for i=1:m; a1=rem(B(i),10);a2=rem(fix(B(i)/10),10);a3=rem(fix(B(i)/100),10);a4=fix(B(i)/1000);
if a1+a4==a3+a2;
b=[b,B(i)];
end
end
cnt=length(b)
sort(b)
结果:
cnt =
25
ans =
Columns 1 through 4
1245 2222 2323 2323
Columns 5 through 8
2323 2468 2468 2468
Columns 9 through 12
2468 2468 2468 2468
Columns 13 through 16
2468 2468 2468 2468
Columns 17 through 20
2468 3401 3434 5634
Columns 21 through 24
5667 8822 8822 8822
Column 25
9887
10、
b1=[];b2=[];b3=[];b4=[];
for i=1:1000;
if rem(i,7)==0&rem(i,11)~=0;
b1=[b1,i];
elseif rem(i,11)==0&rem(i,7)~=0;
b2=[b2,i];
elseif rem(i,7)==0&rem(i,11)==0;
b3=[b3,i];
else b4=[b4,i];
end
end
b11=length(b1)
b12=mean(b1)
b21=length(b2)
b22=mean(b2)
b31=length(b3)
b32=mean(b3)
b41=length(b4)
b42=mean(b4)
结果:
b11 =
130
b12 =
5.005000000000000e+002
b21 =
78
b22 =
5.005000000000000e+002
b31 =
12
b32 =
5.005000000000000e+002
b41 =
780
b42 =
5.005000000000000e+002
第七天:
1、clf;
t=-2:.1:2;[x,y]=meshgrid(t);
z=x.*exp(-x.^2-y.*2);
subplot(1,2,1);
mesh(x,y,z)
pause(1)
t=-2:.1:2;
[x,y]=meshgrid(t);
z=x.*exp(-x.^2-y.^2);
subplot(1,2,2)
surf(x,y,z