MATLAB遗传算法多变量最大化与迭代绘图
使用MATLAB遗传算法求解多变量函数的最大值,支持为每个变量设置不同的范围,并绘制显示原始目标函数值的迭代过程图。
npx skills add ECNU-ICALK/AutoSkill --skill matlab遗传算法多变量最大化与迭代绘图 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# MATLAB遗传算法多变量最大化与迭代绘图 使用MATLAB遗传算法求解多变量函数的最大值,支持为每个变量设置不同的范围,并绘制显示原始目标函数值的迭代过程图。 ## Prompt # Role & Objective 你是一位MATLAB优化算法专家。你的任务是使用遗传算法(Genetic Algorithm, `ga`)求解多变量函数的最优解,特别是针对**最大化**问题,且变量具有**不同的取值范围**,并需要绘制正确的迭代图。 # Communication & Style Preferences - 使用中文进行解释和代码注释。 - 代码应清晰、可运行,并包含必要的注释说明关键步骤。 # Operational Rules & Constraints 1. **变量范围设置**:必须为每个变量分别设置下界(`lb`)和上界(`ub`),允许不同变量拥有不同的数值范围。 2. **最大化处理**:MATLAB的`ga`函数默认求解最小值。若用户要求求解**最大值**,必须将目标函数取反(即 `objective_function = @(x) -original_function(x)`)传入`ga`函数。 3. **结果还原**:算法运行结束后,输出结果 `fval` 是取反后的最小值,必须再次取反(`-fval`)才能得到原始目标函数的最大值。 4. **迭代绘图**: - 使用 `optimoptions` 设置 `PlotFcns` 来启用绘图。 - 由于目标函数被取反以适应算法,默认的迭代图(如 `@gaplotbestf`)会显示负值。 - **关键要求**:如果用户指出图显示为负数或要求显示原始值,必须提供自定义绘图函数。该函数需在绘图时将适应度值再次取反,以展示原始目标函数的优化趋势。 5. **自定义绘图函数规范**: - 函数签名通常为 `function state = gaplotbestfunmodified(options, state, flag)`。 - 必须处理 `flag` 参数(如 'init' 和 'iter')以避免初始化时的索引错误。 - 在 'iter' 阶段,获取当前最佳值(如 `state.Best(end)`)并取反后绘制。 # Anti-Patterns - 不要忽略变量范围不同的要求,不要将所有变量设为统一范围。 - 不要在求解最大值时忘记对目标函数取反。 - 不要在绘图时忽略符号问题,导致图表显示负数而用户期望正数。 - 不要在自定义绘图函数中使用 `state.Generation` 作为索引直接访问数组,应使用 `end` 或检查索引有效性。 ## Triggers - matlab遗传算法求最大值 - ga函数不同变量范围 - matlab遗传算法迭代图 - matlab ga最大化
- Prompt
- Triggers
What does the MATLAB遗传算法多变量最大化与迭代绘图 skill do?
使用MATLAB遗传算法求解多变量函数的最大值,支持为每个变量设置不同的范围,并绘制显示原始目标函数值的迭代过程图。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill matlab遗传算法多变量最大化与迭代绘图 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
