matlab seventh homework


习题8.1

a

% 很明显题目是个泊松分布,均值lambda=5
% i
p_8 = poisspdf(8,5)
fprintf('the probability of 8 calls per minute is %f',[p_8])
% ii
p_2 = poisspdf(2,5)
fprintf('the probability of 2 calls per minute is %f',[p_2])
p_8 =

    0.0653

the probability of 8 calls per minute is 0.065278
p_2 =

    0.0842

the probability of 2 calls per minute is 0.084224

b

% 这题也是一个泊松分布,lambda = 10
% 获得一个busy signal就是指每分钟的电话数多于这个均值10 
p_busySignal = 1 - sum(poisspdf(0:10,5))
fprintf('the probability of getting a busy signalis %f',[p_busySignal])
p_busySignal =

    0.0137

the probability of getting a busy signalis 0.013695

习题8.4

a

% 求均值和方差
[underWeight_mean,underWeight_variance] = binostat(24,0.2)
underWeight_mean =

    4.8000


underWeight_variance =

    3.8400

b

% 不超过两个item underweight 的概率
p_NMT_TwoUnderWeight = sum(binopdf(0:2,24,0.2))
p_NMT_TwoUnderWeight =

    0.1145

c

% 没有一个item underweights 的概率
p_None_UnderWeight = binopdf(0,24,0.2)
p_None_UnderWeight =

    0.0047

d

% 画出under items的数量的概率分布函数和累计概率分布函数
n = 1:24;
pb = binopdf(n,24,0.2);
plot([n;n],[zeros(1,24);pb],'k')

png

%累计概率分布函数
cpb = binocdf(1:24,24,0.2);
plot([n;n],[zeros(1,24);cpb],'k')

png

习题8.7

x = [2.5629,2.5630,2.5628,2.5634,2.5619,2.5613,2.5630,2.5628,2.5623,2.5631,2.5635,2.5623];
x_mean = mean(x);
x_std = std(x);
USL = 2.565;
LSL = 2.560;
PCR = (USL-LSL)/(6*x_std)
PCR_k = min((USL-x_mean)/(3*x_std),(x_mean-LSL)/(3*x_std))
p = 1 - normcdf((USL-x_mean)/x_std,0,1) + normcdf((LSL-x_mean)/x_std,0,1)
PCR =

    1.3103


PCR_k =

    1.2099


ans =

   1.5351e-04

从上面我们发现 \(PCR\) 和 \(PCK_k\) 相差了 0.1左右,应该不算是集中的

习题8.10

a

% 根据函数形式求出所有beta_j来最佳拟合y
y = [144 142 124 64 96 74 136 54 92 96 92 82 76 68]';
x_1 = [18 24 12 30 30 26 26 22 22 14 10 10 6 6]';
x_2 = [52 40 40 48 32 56 24 64 16 64 56 24 48 32]';
X = [ones(length(y),1),x_1,x_2,x_1.^2,x_2.^2,x_1.*x_2];
beta = regress(y,X)
beta =

 -288.2799
   24.1642
   11.5114
   -0.5073
   -0.1181
   -0.1349

b

% 画 surface
x_11 = linspace(min(x_1),max(x_1),1000);
x_22 = linspace(min(x_2),max(x_2),1000);
[x_mesh1,x_mesh2] = meshgrid(x_11,x_22);
y_ = beta(1) + beta(2)*x_mesh1 + beta(3)*x_mesh2 + beta(4)*(x_mesh1.^2) + beta(5)*(x_mesh2.^2) + beta(6)*x_mesh1.*x_mesh2;
surf(x_mesh1,x_mesh2,y_)

png

% 画contour
contour(x_mesh1,x_mesh2,y_)

png

c

先尝试采用暴力解法

% 找到最大值对应的column 和 row
max_y = max(max(y_))
[row,col] = find(max_y == y_)
max_y =

  157.2292


row =

        2294


col =

        2659
x_1max = x_mesh1(row,col)
x_2max = x_mesh2(row,col)
x_1max =

   18.7610


x_2max =

   38.0172

下面用另一种方法求最大值,matlab中提供了fminsearch()这个函数求最小值,将原函数前面加个负号,就可以通过fminsearch()来求解了。

f_beta = @(x)(-(beta(1) + beta(2)*x(1) + beta(3)*x(2) + beta(4)*x(1)^2 + beta(5)*x(2)^2 + beta(6)*x(1)*x(2)))
f_beta =

  function_handle with value:

    @(x)(-(beta(1)+beta(2)*x(1)+beta(3)*x(2)+beta(4)*x(1)^2+beta(5)*x(2)^2+beta(6)*x(1)*x(2)))
[x,fval]=fminsearch(f_beta,[0,0])
x =

   18.7635   38.0155


fval =

 -157.2292
fprintf('when y is maximum value x_1 = %f ,x_2 = %f',[x])
when y is maximum value x_1 = 18.763514 ,x_2 = 38.015484

文章作者: lovelyfrog
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 lovelyfrog !
 上一篇
matlab 单词本 matlab 单词本
word meaning undamped 不衰减的 angular coordinate 角坐标 pendulum 摆动 spring 弹簧 damper 阻尼器 excitation 激励 proto
2017-12-06
下一篇 
我关于SVM的一点理解 我关于SVM的一点理解
我关于SVM的一点理解前言最近两天因为要用到SVM所以比较深入的了解了一下这个算法,查阅了很多资料,发现很多大牛的作品,比如pluskid的支持向量机系列(听说他后来去了MIT),还有邵正将的SVM系列,台大林轩田老师的机器学习基石(
2017-11-27
  目录