实验 07 · MATLAB 画图
可复现的 MATLAB 画图
绘制函数图像,保存可复现结果,并解释 element-wise 平方。
核心问题
函数图像能告诉我们什么?如何让图像结果可以复现?
复用技能
- linspace
- plot
- legend
- saveas
- x.^2
主要任务
- 运行 plot_functions.m。
- 保存 figures/lab07-functions.png。
- 添加一个新函数并解释图像变化。
提交内容
- labs/lab07/plot_functions.m
- figures/lab07-functions.png
- notes/lab07-notes.md
完整讲义
实验 7:可复现的 MATLAB 画图
数学问题
函数图像能告诉我们什么?如何让图像结果可以复现?
复用前面技能
- 用 PowerShell 进入课程根目录。
- 用 VS Code 编辑 MATLAB 文件。
- 用 Codex 解释或改进代码。
- 用共享文件夹保存笔记和输出。
- 识别实验 6 中用过的 MATLAB element-wise 运算。
任务
- 打开课程根目录:
``powershell cd Desktop\codex-matlab-class mkdir labs\lab07 code . ``
- 将
starters/lab07/plot_functions.m复制到labs/lab07/。 - 在 MATLAB 中运行:
``matlab run("labs/lab07/plot_functions.m") ``
- 修改脚本,让它把图像保存到:
``text figures/lab07-functions.png ``
- 让 Codex 解释为什么 MATLAB 使用
x.^2。 - 添加一个新函数,可以选择
cos(x)或exp(-x.^2)。 - 修改区间,并解释图像如何变化。
Codex 提示词要求
使用并记录一个类似提示词:
Please improve labs/lab07/plot_functions.m so it saves the figure to
figures/lab07-functions.png. Do not change the mathematical meaning.
Explain the changes for a beginner MATLAB student.
提交内容
labs/lab07/plot_functions.mfigures/lab07-functions.pngnotes/lab07-notes.md
笔记要求
在 notes/lab07-notes.md 中包括:
- 运行命令;
- Codex 提示词;
- 你添加了哪个函数;
x^2在哪里递增;sin(x)在哪里穿过零点;- 为什么需要
.^。