MATLAB用不同的线型和颜色在同一坐标内绘制区间【0:6】上的曲线y=2sin(2pix)及其包络线,和正弦曲线y=sin(pi *x),并对每条曲线进行标记
时间: 2024-05-28 22:12:11 浏览: 194
可以使用MATLAB中的plot函数来绘制曲线,使用hold函数来保持原有图像,使用legend函数添加图例,代码如下:
```
x = linspace(0, 6, 1000); % 生成区间[0,6]上的1000个点
y1 = 2 * sin(2 * pi * x); % 计算y1值
y2 = sin(pi * x); % 计算y2值
upper_bound = 2; % 包络线上界
lower_bound = -2; % 包络线下界
envelope = [upper_bound * ones(1, 500), linspace(upper_bound, lower_bound, 1000), lower_bound * ones(1, 500)]; % 计算包络线
plot(x, y1, 'r-', 'LineWidth', 1.5, 'DisplayName', 'y=2sin(2πx)'); % 绘制y1曲线
hold on % 保持原有图像
plot(x, envelope, 'b--', 'LineWidth', 1, 'DisplayName', '包络线'); % 绘制包络线
plot(x, y2, 'm-.', 'LineWidth', 1, 'DisplayName', 'y=sin(πx)'); % 绘制y2曲线
legend('Location', 'south', 'FontSize', 12); % 添加图例
xlabel('x', 'FontSize', 14); % 添加x轴标签
ylabel('y', 'FontSize', 14); % 添加y轴标签
title('曲线绘制', 'FontSize', 16); % 添加标题
```
运行结果如下图所示:

阅读全文
相关推荐



















