MATLAB数据建模Week10

MATLAB数据建模Week10

拿走不谢

1、某校60名学生的一次考试成绩如下: 93 75 83 93 91 85 84 82 77 76 77 95 94 89 91 88 86 83 96 81 79 97 78 75 67 69 68 84 83 81 75 66 85 70 94 84 83 82 80 78 74 73 76 70 86 76 90 89 71 66 86 73 80 94 79 78 77 63 53 55 (1) 计算均值、标准差、极差、偏度、峰度,画出直方图; (2) 检验分布的正态性; (3) 若检验符合正态分布,估计正态分布的参数并检验参数.

scores = [93 75 83 93 91 85 84 82 77 76 77 95 94 89 91 88 86 83 96 81 79 97 78 75 67 69 68 84 83 81 75 66 85 70 94 84 83 82 80 78 74 73 76 70 86 76 90 89 71 66 86 73 80 94 79 78 77 63 53 55];

mean_score = mean(scores);


std_deviation = std(scores);


range_score = range(scores);


skewness_score = skewness(scores);


kurtosis_score = kurtosis(scores);

histogram(scores, 'Normalization', 'probability');
title('Histogram of Scores');
xlabel('Scores');
ylabel('Probability');

figure;
normplot(scores);


[h, p] = chi2gof(scores, 'cdf', @normcdf);
disp(['Chi-square goodness of fit test p-value: ', num2str(p)]);
if p > 0.05

    mu_estimate = mean_score;
    sigma_estimate = std_deviation;
    


else
    disp('The data does not follow a normal distribution.');
end

2、试分别绘制出λ=1,5,10时Poisson分布的概率密度函数与分布函数的图形。


lambda_values = [1, 5, 10];


x_values = 0:20;


figure;

subplot(2, 1, 1);
for i = 1:length(lambda_values)
    lambda = lambda_values(i);

    pdf = poisspdf(x_values, lambda);

    plot(x_values, pdf, 'LineWidth', 2, 'DisplayName', ['\lambda = ', num2str(lambda)]);
    hold on;
end
title('Poisson Distribution Probability Density Function');
xlabel('x');
ylabel('Probability');
legend('show');
grid on;


subplot(2, 1, 2);
for i = 1:length(lambda_values)
    lambda = lambda_values(i);

    cdf = poisscdf(x_values, lambda);

    plot(x_values, cdf, 'LineWidth', 2, 'DisplayName', ['\lambda = ', num2str(lambda)]);
    hold on;
end
title('Poisson Distribution Cumulative Distribution Function');
xlabel('x');
ylabel('Cumulative Probability');
legend('show');
grid on;


sgtitle('Poisson Distribution Probability Density Function and Cumulative Distribution Function');

3、设,X~N(1,4)求以下事件的概率: (1)P{X<5} (2)P{0

mu = 1;
sigma = 2;



prob1 = normcdf(5, mu, sigma);


prob2 = normcdf(1.6, mu, sigma) - normcdf(0, mu, sigma);


disp(['P{X < 5} = ', num2str(prob1)]);
disp(['P{0 < X <= 1.6} = ', num2str(prob2)]);

4、正常人的脉搏平均为72次/s,某医生测得10例慢性中毒患者的脉搏为(单位:次/s): 54 67 65 68 78 70 69 67 设患者的脉搏服从正态分布,问患者和正常人的脉搏有无显著差异(α=0.05)?


mu_normal = 72; 
sigma_normal = 1; 


pulse_patient = [54, 67, 65, 68, 78, 70, 69, 67];


mu_patient = mean(pulse_patient); % 样本均值
sigma_patient = std(pulse_patient); % 样本标准差


[h, p] = ttest(pulse_patient, mu_normal, 'Alpha', 0.05);


if h == 1
    disp('患者的脉搏与正常人的脉搏有显著差异');
else
    disp('患者的脉搏与正常人的脉搏无显著差异');
end

disp(['p-value = ', num2str(p)]);

5、从某电工器材厂生产的一批保险丝中抽取10根,测试其熔化时间,得到数据如下: 42 65 75 78 71 59 57 68 55 54 设这批保险丝的熔化时间服从正态分布,检验总体方差是否等于12的平方?


melting_times = [42, 65, 75, 78, 71, 59, 57, 68, 55, 54];


given_variance = 12^2;


[h, p] = vartest(melting_times, given_variance, 'Alpha', 0.05, 'Tail', 'both');


if h == 1
    disp('总体方差不等于给定值的平方');
else
    disp('总体方差等于给定值的平方');
end

disp(['p-value = ', num2str(p)]);

6、试分别绘制出(μ,σ²)=(0,1),(0,0,1),(0,10),(1,1)时正态分布的概率密度函数与分布函数的图形。


parameters = [
    0, 1;
    0, 0.1;
    0, 10;
    1, 1
];


x_values = -5:0.01:5;


figure;


subplot(2, 1, 1);
for i = 1:size(parameters, 1)
    mu = parameters(i, 1);
    sigma = sqrt(parameters(i, 2));

    pdf = normpdf(x_values, mu, sigma);

    plot(x_values, pdf, 'LineWidth', 2, 'DisplayName', ['\mu = ', num2str(mu), ', \sigma^2 = ', num2str(parameters(i, 2))]);
    hold on;
end
title('Normal Distribution Probability Density Function');
xlabel('x');
ylabel('Probability Density');
legend('show');
grid on;


subplot(2, 1, 2);
for i = 1:size(parameters, 1)
    mu = parameters(i, 1);
    sigma = sqrt(parameters(i, 2));

    cdf = normcdf(x_values, mu, sigma);

    plot(x_values, cdf, 'LineWidth', 2, 'DisplayName', ['\mu = ', num2str(mu), ', \sigma^2 = ', num2str(parameters(i, 2))]);
    hold on;
end
title('Normal Distribution Cumulative Distribution Function');
xlabel('x');
ylabel('Cumulative Probability');
legend('show');
grid on;


sgtitle('Normal Distribution Probability Density Function and Cumulative Distribution Function');

7、试求以下分布的上侧0.05分位数(注意与下侧分位数的区别): (1)标准正态分布:μ0.05 (2)卡方分布:χ^2 0.05(5) (3)t分布:t0.05(10)

mu = 0;
sigma = 1;
alpha = 0.05;
upper_quantile = norminv(1 - alpha, mu, sigma);
disp(['标准正态分布的上侧0.05分位数为:', num2str(upper_quantile)]);

nu = 5;
alpha = 0.05;
upper_quantile = chi2inv(1 - alpha, nu);
disp(['卡方分布的上侧0.05分位数为:', num2str(upper_quantile)]);

nu = 10; 
alpha = 0.05;
upper_quantile = tinv(1 - alpha, nu);
disp(['t分布的上侧0.05分位数为:', num2str(upper_quantile)]);

8、8、填空题

(1)设在正态总体中抽得一容量为16的样本,这里均未知,为样本方差,则计算的Matlab指令为probability = chi2cdf(nu * threshold, nu);.

(2)随机产生100个服从正态分布的样本数据,并用这些数据估计总体中的参数的置信水平为90%的置信区间,则完成该任务的Matlab指令为[ci_mu,ci_sigma]=normfit(sample_data,0.1).

(3)某种元件的寿命(单位以小时计)服从正态分布,均未知,现测得8只元件的寿命为X=[159, 280, 212, 379, 264, 149, 260, 264],在显著性水平下是否有理由认为元件的平均寿命大于225小时,则完成该假设检验任务的Matlab指令为[h, p, ci, stats] = ttest(X, 225, ‘Tail’, ‘right’, ‘Alpha’, alpha);.

你可能感兴趣的:(matlab,算法,人工智能)