Stephen J.Chapman《MATLAB 编程(第二版) 》第四章
% an input data set containing an arbitrary number % of input values. %
% Record of revisions:
% Date Programmer Description of change
% ==== ========== ===================== % 12/05/97 S. J. Chapman Original code %
% Define variables:
% n -- The number of input samples
% std_dev -- The standard deviation of the input samples % sum_x -- The sum of the input values
% sum_x2 -- The sum of the squares of the input values % x -- An input data value
% xbar -- The average of the input samples % Initialize sums.
n = 0; sum_x = 0; sum_x2 = 0; % Read in first value
x = input('Enter first value: ');
% While Loop to read input values. while x >= 0 % Accumulate sums. n = n + 1; sum_x = sum_x + x; sum_x2 = sum_x2 + x^2; % Read in next value
x = input('Enter next value: '); end
% Calculate the mean and standard deviation x_bar = sum_x / n;
std_dev = sqrt( (n * sum_x2 - sum_x^2) / (n * (n-1)) ); % Tell user.
fprintf('The mean of this data set is: %f\n', x_bar); fprintf('The standard deviation is: %f\n', std_dev); fprintf('The number of data points is: %f\n', n);
5.检测程序为检测这个程序,我们将手工算出一组简单数据的平均数和标准差,然后与程序产生的结果进行比对。如果我们用三个输入值:3,4和5,那么它的平均数和标准差分别为
1N1
=∑xi=×12=4
Ni=13
N∑xi2 (∑xi)
N
N
2
s=
N(N 1)
=1
我们把这些值输入程序后,产生的结果为
>> stats_1
Enter first value: 3 Enter next value: 4 Enter next value: 5 Enter next value: -1
The mean of this data set is: 4.000000 The standard deviation is: 1.000000 The number of data points is: 3.000000
这个结果说明了程序的正确性。在这个例子中,我们并没有完全遵循设计过程。这个失误导致这个软件有一个致命的缺陷。你能指出来它吗?
Stephen J.Chapman《MATLAB 编程(第二版) 》第一章_工学_高等教育_教育专区。Stephen J.Chapman《MATLAB 编程(第二版) 》郑碧波翻译 Matlab 中文论坛首发 http:...
Stephen J.Chapman《MATLAB 编程(第二版) 》第二章Stephen J.Chapman《MATLAB 编程(第二版) 》第二章隐藏>> 郑碧波翻译 Matlab 中文论坛首发 http://www.iLo...
Stephen J.Chapman《MATLAB 编程(第二版) 》第三章Stephen J.Chapman《MATLAB 编程(第二版) 》第三章隐藏>> 郑碧波翻译 Matlab 中文论坛首发 http://www.iLove...
Stephen J.Chapman《MATLAB 编程(第二版) 》第六章Stephen J.Chapman《MATLAB 编程(第二版) 》第六章隐藏>> 郑碧波翻译 Matlab 中文论坛首发 http://www.iLo...
Matlab编程 第四版(Stephen J.Chapman)Quiz部分答案_计算机软件及应用_IT/计算机_专业资料。Matlab编程 第四版 (Stephen J.ChapmanQuiz答案PD...
郑碧波翻译 Matlab 中文论坛首发 http://www.iLoveMatlab.cn 前言 本文为 Stephen J.Chapman《MATLAB 编程(第二版) 》英文影印版的中文译本,这本 书对初学者很...
Chapman 著 邢树军 郑碧波 译 前言郑碧波本文为 Stephen J.Chapman《MATLAB 编程(第二版) 》英文影印版的中文译本,这本 书对初学者很好的入门教材。之前从网...
matlab编程英文版(Stephen J. Chapman )课后答案1_工学_高等教育_教育专区。matlab编程第二版Stephen J. ChapmanMATLAB MATLAB Programming for Enginees Enginees 姓名...
S.J.Chapman《MATLAB编程》中文版修正版_部分7_信息与通信_工程科技_专业资料。...>> cellstring{1} = 'Stephen J. Chapman'; >> cellstring{2} = 'Male'...
S.J.Chapman《MATLAB编程》中文版修正版_部分3_信息与通信_工程科技_专业资料。...Stephen J.Chapman《MAT... 39页 免费 Stephen J.Chapman《MAT... 37页 免...
热门文档