数学实验报告

  |  

文章导航

大一上数学实验报告

第一次实验任务

编写程序,解决下列问题:

程序:

1
2
3
4
5
6
7
8
9
10
11
a=1+3*i;

b=2-i;

a+b

a-b

a*b

a/b

a+b=3.0000 + 2.0000i; a-b=-1.0000 + 4.0000i; a*b=5.0000 + 5.0000i; a/b=-0.2000 + 1.4000i

程序:

1
2
3
4
5
x=-4.5*180/pi;

y=7.6*180/pi;

sin(abs(x)+y)/sqrt(cos(abs(x+y)))

答案:0 - 2.4840i

程序:

1
2
3
4
5
x=1295330000;

y=0.0107;

renkoushu=x*(1+y)^10

答案:1.4408e+009

程序1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
x=0:0.1:10;

y1=sin(x);

y2=cos(x);

y3=exp(x);

y4=log(x);

xlabel('x')

ylabel('y')

plot(x,y1,'r*-',x,y2,'b*-',x,y3,'g*-',x,y4,'m*-')

title('all')

axis([0,10,-2,5])

程序2:

1
2
3
4
5
6
7
8
9
10
11
12
13
x=0:pi/10:2*pi;

y1=sin(x); y2=cos(x);

y3=exp(x); y4=log(x);

subplot(2,2,1); plot(x,y1,'bo-')

subplot(2,2,2); plot(x,y2,'R*:')

subplot(2,2,3); plot(x,y3,'g+')

subplot(2,2,4); plot(x,y4,'mp')

答案:(1)img (2)

5、画出半径为2的圆的图形

程序:

1
2
3
ezplot('x^2+y^2-4',[-3,3,-3,3])

axis equal

答案:

6、随机生成一个3x3矩阵A及3x2矩阵B,计算(1)AB,(2)对B中每个元素平方后得到的矩阵C,(3)sinB,(4) A的行列式,(5)判断A是否可逆,若可逆,计算 A的逆矩阵,(6)解矩阵方程AX=B,(7)矩阵A中第二行元素加1,其余元素不变,得到矩阵D,计算D。

程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
A=rand(3,3)

B=rand(3,2)

A*B

C=A.^2

sin(B)

det(A)

if det(A)~=0

inv(A)

end

X=A\B

A(2,:)=A(2,:)+1;

D=A

结果:

A =

0.8147 0.9134 0.2785

0.9058 0.6324 0.5469

0.1270 0.0975 0.9575

B =

0.9649 0.9572

0.1576 0.4854

0.9706 0.8003

AB =

1.2004 1.4460

1.5045 1.6116

1.0673 0.9352

C =

0.6638 0.8343 0.0776

0.8205 0.3999 0.2991

0.0161 0.0095 0.9168

sinB=

0.8220 0.8176

0.1570 0.4665

0.8252 0.7176

Det(A)= -0.2767

Inv(A)=

-1.9958 3.0630 -1.1690

2.8839 -2.6919 0.6987

-0.0291 -0.1320 1.1282

X =

-2.5775 -1.3591

3.0365 2.0130

1.0462 0.8110

D =

0.8147 0.9134 0.2785

1.9058 1.6324 1.5469

0.1270 0.0975 0.9575

7、设\(y=(x^2 + e^xcosx+[x])/x\),分别计算\(x=1, 3, 5, 7.4\)\(y\)的值。其中\([x]\)表示\(x\)的取整函数。

程序:

1
2
3
x=[1,3,5,7.4];

y=(x.^2+exp(x).*cos(x)+round(x))./x

答案:y =3.4687 ,-2.6282, 14.4198,105.2995

8、已知某地区1-12月份的平均气温为5,8,13,20,25,28,31,33,27,24,19,10,请绘图表示。

程序:

1
2
3
4
5
6
7
x=1:1:12

y=[5,8,13,20,25,28,31,33,27,24,19,10]

plot(x,y,'*b-')

axis([1,12,0,35])

答案:

第二次实验任务:

  1. 某大学本科生就业情况如下:458人考入研究生,60人签到外企或合资企业,184人签到国营大企业,87人签到私人企业,13人自主创业,画出饼图表示之;

程序:

1
2
3
x=[458 60 184 87 13];

pie(x)
  1. 求极限

程序:

1
2
3
4
5
syms x a

fx=((x-a)/(x+a))^x;

limit(fx,x,inf)

答案:exp(-2*a)

  1. 求极限

程序:

1
2
3
4
5
syms x

fx=tan(x)^(1/log(x));

limit(fx,x,0,'left')

答案:e

程序:

1
2
3
4
5
6
7
syms x t

y=(1+1/x)^(2*t*x);

ft=limit(y,x,inf);

diff(ft,x)

答案:0

  1. 展开多项式

程序:

1
2
3
4
5
syms x a b

y=(a+1)^3+(b-1)^2+a+2*b;

expand(y)

答案:y=a^3 + 3a^2 + 4a + b^2 + 2

  1. 分解因式

程序:

1
2
3
4
5
syms x

y=x^5-3*x^4+2*x^2+x-1;

factor(y)

答案:(x - 1)(x^4 - 2x^3 - 2*x^2 + 1)

  1. 求方程的根

程序:

1
2
3
4
5
syms x

y=x^3-2*x+1;

solve(y)

答案:

x= 1; - 5^(1/2)/2 - 1/2;5^(1/2)/2 - 1/2

程序:

1
2
3
4
5
syms x

y=sym('sqrt(x+sqrt(x+sqrt(x)))');

diff(y)

答案:((1/(2x^(1/2)) + 1)/(2(x + x(1/2))(1/2)) + 1)/(2*(x + (x + x(1/2))(1/2))^(1/2))

  1. 求不定积分

程序:

1
2
3
4
5
syms x

y=sym('1/(sqrt(2*x+3)+sqrt(2*x-1))');

ny=int(y)

答案:ny =

-(((3^(1/2) - (2x + 3)^(1/2))(184x - 33^(1/2)(2x - 1)^(3/2) - 403^(1/2)(2x + 3)^(1/2) - 33^(1/2)(2x + 3)^(3/2) + 9(2x - 1)^(3/2)i + (2x + 3)(3/2)i + 63(1/2)(2x + 3)i - 93^(1/2)(2x - 1)(2x + 3)^(1/2) + 84 + 243(1/2)i + 63(1/2)(2x - 1)i - 48(2x + 3)^(1/2)i + 3(2x - 1)(2x + 3)^(1/2)i))/6 - ((2x - 1)^(1/2)(3^(1/2) - (2x + 3)(1/2))(243(1/2) + 43^(1/2)(2x + 3)(1/2)i - 22xi - 60(2x + 3)^(1/2) + 93(1/2)(2x + 3) + 15i))/6)/((3^(1/2) + (2x - 1)^(1/2) - (2x + 3)^(1/2) - i)(3^(1/2) - (2x - 1)^(1/2) - (2x + 3)^(1/2) + i)^3)

程序:

1
2
3
4
5
syms x

y=1/(1+cos(x));

int(y)

答案:tan(x/2)

10 求定积分

程序:

1
2
3
4
5
syms x

y=1/(x*sqrt(log(x)*(1-log(x))));

int(y,x,exp(1/2),exp(3/4))

答案:

4*atan(((1-log(1856295125090727/1125899906842624))^(1/2)-1)/log(1856295125090727/1125899906842624)^(1/2))-4*atan(((1-log(595882530372511/281474976710656))^(1/2)-1)/log(595882530372511/281474976710656)^(1/2))

  1. 解方程组

程序:

1
2
3
4
5
6
7
syms x y

f1=sym('2*x+y-8');

f2=sym('x-3*y-1');

[x,y]=solve(f1,f2)

答案:x =25/7 y =6/7

  1. 求和

程序:

1
2
3
4
5
6
7
8
9
s=0

for k=1:20

s=s+1/k^2

end

s

答案:s =1.5962

程序:

1
2
3
syms x

taylor(cos(2*x),16,pi/6)

答案:

(23^(1/2)(x - pi/6)^3)/3 - 3(1/2)(x - pi/6) - (23(1/2)(x - pi/6)^5)/15 + (43(1/2)(x - pi/6)^7)/315 - (23(1/2)(x - pi/6)^9)/2835 + (43(1/2)(x - pi/6)^11)/155925 - (43(1/2)(x - pi/6)^13)/6081075 + (83^(1/2)(x - pi/6)^15)/638512875 - (x - pi/6)^2 + (x - pi/6)^4/3 - (2(x - pi/6)^6)/45 + (x - pi/6)^8/315 - (2(x - pi/6)^10)/14175 + (2(x - pi/6)^12)/467775 - (4*(x - pi/6)^14)/42567525 + 1/2

第三次实验任务:

1、 每门课程考试阅卷完毕,任课教师都要对各班的考试成绩进行统计,统计内容包括:全班人数,总得分,平均得分,不及格的人数及90分(包括90分)以上的人数.请编制程序解决这一问题,并自给一组数据验证程序的正确性.要求:使用者在提示下通过键盘输入学生成绩,计算机自动处理后,显示需要的结果.

程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
a=input('请输入a[n]=');

[m,n]=size(a);

x=0;p=0;s=0;

for i=1:n

x=x+a(i);

if a(i)<60

​ p=p+1;

elseif a(i)>=90

​ s=s+1;

end

end

y=x/n;

fprintf('n=%.0f,x=%.1f,y=%.3f,p=%.0f,s=%.0f\n',n,x,y,p,s)

答案:

(1) 数据:a[n]=[68 98 95 64 37 55 73 69 100 90]

(2) 结果:n=10(人数),x=749.0(总分),y=74.900(均分),p=2(不及格),s=4(及格)

2、 课后习题任选2题.

(1).水仙花数:

程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for a=1:9

for b=0:9

for c=0:9

m=a*100+b*10+c;

if m==a^3+b^3+c^3

fprintf('m=%.0f\n',m)

end

end

end

end

答案:m=153 m=370 m=371 m=407

(2).哥德巴赫猜想

程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
x=input('输入一个大于二的偶数x: ');

p=primes(x);

i=1;

while p(i)<=x/2

q=x-p(i);

if any(q==p)

fprintf('%d=%d+%d\n',x,p(i),q)

end

i=i+1;

end

答案:输入一个大于二的偶数x:46

46=3+43

46=5+41

46=17+29

46=23+23

3、编写猜数游戏程序:

首先由计算机随机产生一个 [1,100] 之间的一个整数,然后由用户猜测所产生的这个数。根据用户猜测的情况给出不同的提示,如果猜测的数大于产生的数,则显示 “High” ,小于则显示 “ Low ” ,等于则显示 “You won!”,同时退出游戏。用户最多有 7 次机会。

程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
x=round(100*rand);

s=1;

while s<=7

a=input('请输入这个数');

if a>x

fprintf('High\n')

elseif a<x

fprintf('Low\n')

else

fprintf('You won!\n')

break

end

s=s+1;

end

fprintf('game over')

4、编写程序解决下列问题

Fibonacci数组元素满足Fibonacci规则:imgimg

(1) 用循环语句形成前20个分量的数组;

程序:

1
2
3
4
5
6
7
8
9
a(1)=1;a(2)=1;

for n=1:20

a(n+2)=a(n+1)+a(n);

end

a(1:20)

答案:

1 至 8 列

​ 1 1 2 3 5 8 13 21

9 至 16 列

​ 34 55 89 144 233 377 610 987

17 至 20 列

​ 1597 2584 4181 6765

(2) 求该数组中第一个大于10000的数.

程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
a(1)=1;a(2)=1;

i=2;

while a(i)<=10000

a(i+1)=a(i-1)+a(i);

i=i+1;

end

a(i)

答案:10946

5、

(1)编写一个function函数,调用该函数,可以求一组数的最大值及最小值.

(2)通过键盘输入一组数,利用(1)编写的function函数,得出最大最小数.

程序:

1
2
3
4
5
6
7
function p=qiuzhi(a)

n=min(a);

m=max(a);

p=[m,n];

结果:

qiuzhi([9,43,87,-19,56,36,-7])

ans =

87 -19

本站总访问量 您是第位访客