具有动态约束的 MatLab 曲线拟合

发布于 2024-12-27 22:47:50 字数 178 浏览 2 评论 0原文

我想使用 lsqcurvefit 函数拟合曲线。这就像这个问题:

y = a1 * x + a2 * z
s.t
a1 > 0
a2 > 0
a1 + a2 <= some number

Matlab 中是否可能有这样的动态约束,或者我应该使用其他包吗?

I want to fit a curve using the lsqcurvefit function. It is something like this problem:

y = a1 * x + a2 * z
s.t
a1 > 0
a2 > 0
a1 + a2 <= some number

Is it possible to have such dynamic constraints in matlab or should i use some other package?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染年凉城似染瑾 2025-01-03 22:47:50

只要约束是线性等式或不等式,lsqlin 就是解决您问题的工具。您已经描述了线性情况,因此这是正确的解决方案。

如果您展示了一个具有非线性约束的示例,那么您将被迫使用 fmincon (如 Marcin 所建议的),但这对于完全线性问题来说有点过大了。当然,fmincon 的效率也会大大降低,因为 fmincon 不知道您的目标是约束下的线性最小二乘法。

最后,为了使用 fmincon,您需要将目标定义为残差平方和。后一步对于 lsqlin 来说不是必需的,因为 lsqlin 是专门为解决您的问题类别而设计的。

lsqlin is the tool for your problem, as long as the constraints are linear equalities or inequalities. You have described the linear case, so this is the correct solution.

Had you shown an example with nonlinear constraints, you would then be forced to use fmincon (as suggested by Marcin) but this would be overkill for a fully linear problem. And of course, fmincon would also be considerably less efficient, because fmincon does not know that your objective is a linear least squares under constraints.

Finally, in order to use fmincon, you would need to define an objective as a sum of squares of the residuals. This latter step is not necessary for lsqlin, since lsqlin is designed explicitly to solve your class of problem.

相守太难 2025-01-03 22:47:50

fmincon 可能就是您想要的。约束是一个单独的函数,因此您可以在其中塞入任何内容,任意数量的约束,只要您可以将它们表达为方程即可。

fmincon is probably what you want. The constraints are a separate function, so you can cram anything in there, any number of constraints, as long as you can express them as equations .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文