% 设置模拟参数 N = 10000; mu_p = 198900; sigma_p = sqrt(4500.2); mu_f = 120050.28; sigma_f = sqrt(3900.6); mu_r =30710; sigma_r = sqrt(892.6); mu_s = -1572.5; sigma_s = sqrt(60.2); % 生成随机样本 p_cost = normrnd(mu_p, sigma_p, [N, 1]); f_cost = normrnd(mu_f, sigma_f, [N, 1]); r_cost = normrnd(mu_r, sigma_r, [N, 1]); s_cost = normrnd(mu_s, sigma_s, [N, 1]); % 计算总成本 total_cost = p_cost + f_cost + r_cost + s_cost; % 绘制总成本直方图 histogram(total_cost, 'Normalization', 'pdf'); xlabel('Total Cost (Millions of Yuan)'); ylabel('Probability Density'); % 输出统计信息 fprintf('Mean Total Cost: %.2f (Millions of Yuan)\n', mean(total_cost)); fprintf('Standard Deviation of Total Cost: %.2f (Millions of Yuan)\n', std(total_cost));输出结果横坐标的图形扩大一倍
时间: 2024-02-17 20:00:47 浏览: 100
wm_sqrt.rar_ROOT_sqrt fixed
可以使用 `gca` 函数获取当前图形的句柄,然后使用 `xlim` 函数修改横坐标范围。例如,将横坐标范围扩大一倍,可以在代码最后添加以下语句:
```matlab
ax = gca;
xlim(ax, ax.XLim * 2);
```
修改后的完整代码如下:
```matlab
% 设置模拟参数
N = 10000;
mu_p = 198900;
sigma_p = sqrt(4500.2);
mu_f = 120050.28;
sigma_f = sqrt(3900.6);
mu_r = 30710;
sigma_r = sqrt(892.6);
mu_s = -1572.5;
sigma_s = sqrt(60.2);
% 生成随机样本
p_cost = normrnd(mu_p, sigma_p, [N, 1]);
f_cost = normrnd(mu_f, sigma_f, [N, 1]);
r_cost = normrnd(mu_r, sigma_r, [N, 1]);
s_cost = normrnd(mu_s, sigma_s, [N, 1]);
% 计算总成本
total_cost = p_cost + f_cost + r_cost + s_cost;
% 绘制总成本直方图
histogram(total_cost, 'Normalization', 'pdf');
xlabel('Total Cost (Millions of Yuan)');
ylabel('Probability Density');
% 输出统计信息
fprintf('Mean Total Cost: %.2f (Millions of Yuan)\n', mean(total_cost));
fprintf('Standard Deviation of Total Cost: %.2f (Millions of Yuan)\n', std(total_cost));
% 扩大横坐标范围
ax = gca;
xlim(ax, ax.XLim * 2);
```
运行修改后的代码后,横坐标范围将扩大一倍。
阅读全文