我是靠谱客的博主 大方香菇,这篇文章主要介绍【工程数据分析】实验一工程数据分析实验1,现在分享给大家,希望可以做个参考。

工程数据分析实验1

用Matlab进行数据分析, 绘图

实验内容

请添加图片描述

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
x = 1:8; y = [12 27 34 48 67 79 89 109]; y1 = 12.*x; y2 = 12.*x+1; y3 = 12.*x-1; y4 = 12.5.*x; m1 = sum((y1-y).^2); m2 = sum((y2-y).^2); m3 = sum((y3-y).^2); m4 = sum((y4-y).^2); m = [m1,m2,m3,m4] n = min(m); for i = 1:4 if m(i) == n fprintf("误差的平方和最小的为第%d个函数关系n",i); end end

请添加图片描述

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
x = newton(1.500, 0.000000001, 1000000); fprintf('近似解为x=%0.10fn',x); fprintf("n"); % 牛顿迭代函数(用于求非线性方程的近似解) function x=newton(x,c,N) for i=1:N f = x.^3 + 2.*x.^2+10.*x-20; df = 3.*x.^2+4.*x+10; x1 = x-f./df; if abs(x1-x)<c break; end x=x1; end end

请添加图片描述

复制代码
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
83
84
85
86
87
88
89
xls1 = xlsread('yhgspj.xls'); % 均值 fprintf('求各列均值n'); M = mean(xls1,1) % 中位数 fprintf('求各列中位数n'); m = median(xls1,1) % 最高价 fprintf('求各列最高价n'); max1 = max(xls1) % 最低价 fprintf('求各列最低价n'); min1 = min(xls1) % 用条形图绘制 d = [M;m;max1;min1]; % a = ['均值';'中位数';'最大值';'最小值']; % b = bar(d); createp(d); % 求方差 fprintf('求各列方差n'); V = var(xls1) % S = std(xls1) bank = ['中国银行','交通银行','工商银行','建设银行','农业银行']; minbank = min(V); n = length(V); for i=1:n if V(i) == minbank switch(i) case 1 ss = bank(1:4); break; case 2 ss = bank(5:8); break; case 3 ss = bank(9:12); break; case 4 ss = bank(13:16); break; otherwise ss = bank(17:end); end fprintf('从6家银行收盘价的方差来看, %s的股票价格相对平稳, 其方差最小: %0.4f',ss, minbank); end end % 绘画出6家银行的条形图函数 function createp(ymatrix1) % YMATRIX1: bar 矩阵数据 % 创建 figure figure1 = figure; % 创建 axes axes1 = axes('Parent',figure1,... 'Position',[0.0742857142857143 0.0571428571428572 0.868571428571428 0.878095238095239]); hold(axes1,'on'); % 使用 bar 的矩阵输入创建多行 bar1 = bar(ymatrix1,'Parent',axes1); set(bar1(5),'DisplayName','农业银行'); set(bar1(4),'DisplayName','建设银行'); set(bar1(3),'DisplayName','工商银行'); set(bar1(2),'DisplayName','交通银行'); set(bar1(1),'DisplayName','中国银行'); % 创建 ylabel ylabel({'价格单位: 元'}); % 创建 title title({'6家银行的收盘价'}); box(axes1,'on'); % 设置其余坐标区属性 set(axes1,'XTick',[1 2 3 4],'XTickLabel',{'均值','中位数','最大值','最小值'}); % 创建 legend legend1 = legend(axes1,'show'); set(legend1,... 'Position',[0.755595230339078 0.716507931966636 0.176785716329302 0.204761909303211]); end

总代码

复制代码
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
% 实验一 fprintf("实验一:n"); x = 1:8; y = [12 27 34 48 67 79 89 109]; y1 = 12.*x; y2 = 12.*x+1; y3 = 12.*x-1; y4 = 12.5.*x; m1 = sum((y1-y).^2); m2 = sum((y2-y).^2); m3 = sum((y3-y).^2); m4 = sum((y4-y).^2); m = [m1,m2,m3,m4] n = min(m); for i = 1:4 if m(i) == n fprintf("误差的平方和最小的为第%d个函数关系n",i); end end fprintf("n"); % 实验二 fprintf("实验二:n"); x = newton(1.500, 0.000000001, 1000000); fprintf('近似解为x=%0.10fn',x); fprintf("n"); % 实验三 fprintf("实验三:n"); xls1 = xlsread('yhgspj.xls'); % 均值 fprintf('求各列均值n'); M = mean(xls1,1) % 中位数 fprintf('求各列中位数n'); m = median(xls1,1) % 最高价 fprintf('求各列最高价n'); max1 = max(xls1) % 最低价 fprintf('求各列最低价n'); min1 = min(xls1) % 用条形图绘制 d = [M;m;max1;min1]; % a = ['均值';'中位数';'最大值';'最小值']; % b = bar(d); createp(d); % 求方差 fprintf('求各列方差n'); V = var(xls1) % S = std(xls1) bank = ['中国银行','交通银行','工商银行','建设银行','农业银行']; minbank = min(V); n = length(V); for i=1:n if V(i) == minbank switch(i) case 1 ss = bank(1:4); break; case 2 ss = bank(5:8); break; case 3 ss = bank(9:12); break; case 4 ss = bank(13:16); break; otherwise ss = bank(17:end); end fprintf('从6家银行收盘价的方差来看, %s的股票价格相对平稳, 其方差最小: %0.4f',ss, minbank); end end % 牛顿迭代函数(用于求非线性方程的近似解) function x=newton(x,c,N) for i=1:N f = x.^3 + 2.*x.^2+10.*x-20; df = 3.*x.^2+4.*x+10; x1 = x-f./df; if abs(x1-x)<c break; end x=x1; end end % 绘画出6家银行的条形图函数 function createp(ymatrix1) % YMATRIX1: bar 矩阵数据 % 创建 figure figure1 = figure; % 创建 axes axes1 = axes('Parent',figure1,... 'Position',[0.0742857142857143 0.0571428571428572 0.868571428571428 0.878095238095239]); hold(axes1,'on'); % 使用 bar 的矩阵输入创建多行 bar1 = bar(ymatrix1,'Parent',axes1); set(bar1(5),'DisplayName','农业银行'); set(bar1(4),'DisplayName','建设银行'); set(bar1(3),'DisplayName','工商银行'); set(bar1(2),'DisplayName','交通银行'); set(bar1(1),'DisplayName','中国银行'); % 创建 ylabel ylabel({'价格单位: 元'}); % 创建 title title({'6家银行的收盘价'}); box(axes1,'on'); % 设置其余坐标区属性 set(axes1,'XTick',[1 2 3 4],'XTickLabel',{'均值','中位数','最大值','最小值'}); % 创建 legend legend1 = legend(axes1,'show'); set(legend1,... 'Position',[0.755595230339078 0.716507931966636 0.176785716329302 0.204761909303211]); end

输出结果 :

复制代码
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
>> s1 实验一: m = 305 247 379 140 误差的平方和最小的为第4个函数关系 实验二: 近似解为x=1.3688081078 实验三: 求各列均值 M = 3.3820 5.4937 4.2080 4.9017 3.0805 求各列中位数 m = 3.3900 5.5000 4.2500 4.8200 3.1100 求各列最高价 max1 = 3.8900 6.2100 4.5100 5.6400 3.2500 求各列最低价 min1 = 3.1200 5.0800 3.9700 4.5300 2.8900 求各列方差 V = 0.0364 0.0681 0.0208 0.0710 0.0110 从6家银行收盘价的方差来看, 农业银行的股票价格相对平稳, 其方差最小: 0.0110>>

条形图 :

请添加图片描述


附加数据表格

表格数据(Excel) : yhgspj.xls

日期中国银行(601988)交通银行(601328)工商银行(601398)建设银行(601939)农业银行(601288)
2016/3/313.45.574.294.853.2
2016/3/303.45.584.324.93.2
2016/3/293.345.464.254.813.15
2016/3/283.355.54.34.823.15
2016/3/253.365.514.284.843.16
2016/3/243.355.514.264.833.16
2016/3/233.395.594.34.883.18
2016/3/223.45.614.294.893.18
2016/3/213.435.654.314.93.21
2016/3/183.435.664.34.863.22
2016/3/173.435.724.294.873.21
2016/3/163.445.774.324.863.25
2016/3/153.385.634.264.813.19
2016/3/143.45.494.34.83.19
2016/3/113.45.494.344.763.19
2016/3/103.355.44.324.763.15
2016/3/93.435.534.414.773.21
2016/3/83.45.524.334.793.18
2016/3/73.395.54.294.813.18
2016/3/43.45.534.314.843.2
2016/3/33.285.334.134.713.08
2016/3/23.265.314.114.73.05
2016/3/13.25.184.034.572.99
2016/2/293.175.174.034.532.99
2016/2/263.155.164.024.622.96
2016/2/253.125.084.014.572.92
2016/2/243.245.324.054.732.98
2016/2/233.245.324.054.732.98
2016/2/223.295.394.084.783
2016/2/193.225.284.024.692.95
2016/2/183.235.274.064.722.97
2016/2/173.245.284.044.732.97
2016/2/163.235.284.054.732.94
2016/2/153.135.153.974.622.89
2016/2/53.185.24.014.692.92
2016/2/43.195.214.024.712.93
2016/2/33.175.174.014.682.92
2016/2/23.25.254.054.732.96
2016/2/13.175.24.034.72.94
2016/1/293.225.354.14.812.99
2016/1/283.165.224.054.752.91
2016/1/273.225.254.114.832.95
2016/1/263.245.234.084.872.95
2016/1/253.445.524.235.073.1
2016/1/223.455.524.225.053.11
2016/1/213.435.484.185.033.09
2016/1/203.475.554.225.093.11
2016/1/193.535.634.255.153.11
2016/1/183.465.524.195.043.07
2016/1/153.485.564.235.093.07
2016/1/143.595.764.315.213.12
2016/1/133.585.754.35.23.12
2016/1/123.635.814.325.273.13
2016/1/113.655.84.325.33.09
2016/1/83.86.034.465.543.16
2016/1/73.795.944.435.493.11
2016/1/63.896.214.515.643.18
2016/1/53.866.164.475.583.16
2016/1/43.876.074.455.63.12

以上是学习过程中的实验内容, 仅供学习参考, 可能有错误之处.

最后

以上就是大方香菇最近收集整理的关于【工程数据分析】实验一工程数据分析实验1的全部内容,更多相关【工程数据分析】实验一工程数据分析实验1内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部