-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomework_ch6.m
More file actions
82 lines (68 loc) · 1.72 KB
/
Homework_ch6.m
File metadata and controls
82 lines (68 loc) · 1.72 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
%5.25日作业
%------------------------------分界符----------------------------------%
%第一题
x_1=rand(1,30000);
%第一问
disp('均值为');mu=mean(x_1)
disp('标准差为');sigma=std(x_1)
%第二问
disp('最大值为');max_x=max(x_1)
disp('最小值为');min_x=min(x_1)
c_1=x_1>0.5;
cc_1=sum(c_1)
y_1=cc_1/30000;
disp('所占比例为');y_1
%------------------------------分界符----------------------------------%
%第二题
%第一问
P=randi([45,95],100,5);
disp('最大值及其序号')
[max_2,num]=max(P)
disp('最小值及其序号')
[max_2,num_2]=min(P)
%第二问
disp('均值为')
mu_2=mean(P)
disp('标准差为')
sigma_2=std(P)
%第三问
to=sum(P,2)
[max_to,num_to]=max(to)
[min_to,num_to]=min(to)
%第四问
[score,num]=sort(to,1,"descend")
%------------------------------分界符----------------------------------%
%第三题
P1=[1,2,4,0,5];P2=[0,0,0,1,2];P3=[0,0,1,2,3];
%第一问
Px=P1+P2+P3;
%第二问
disp('多项式的根为')
X=roots(Px)
%第三问
x=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];
disp('若以矩阵每个元素为自变量时')
y1=polyval(Px,x)
%第四问
disp('若以整个矩阵为自变量时')
y2=polyvalm(Px,x)
%------------------------------分界符----------------------------------%
%第四题
time=6:2:18;
t1=[18,20,22,25,30,28,24];
t2=[15,19,24,28,34,32,30];
new_t1=6:0.5:18;
p1=spline(time,t1,new_t1);
plot(time,t1,'o',new_t1,p1,'b-')
hold on
new_t2=6:0.5:18;
p2=spline(time,t2,new_t2);
plot(time,t2,'o',new_t2,p2,'b-')
%------------------------------分界符----------------------------------%
%第五题
x=[1:10:101];
lgx=log10(x);
p=polyfit(x,lgx,5)
ti=1:10:101;
yi=polyval(p,ti)
plot(x,lgx,':o',ti,yi,'-*')