使用优化的数学建模,第4部分:基于问题的非线性编程
From the series:优化的数学建模
Express and solve a nonlinear optimization problem with the problem-based approach of Optimization Toolbox™. Interactively define the variables, objective function, and constraints to reflect the mathematical statement of the nonlinear program.
首先创建优化问题以解决问题。接下来,定义优化变量及其边界。每个优化变量都有其自己的显示名称,维度,类型和边界。定义一个或多个标量或数组变量以匹配数学语句中使用的变量。
创建目标和约束与论述tion expressions built with the optimization variables. Specify them directly for rational expressions. Specify other expressions with MATLAB®功能并通过转换函数转换为优化表达式。转换设施使使用现有功能可以轻松定义优化问题。
使用显示功能查看完成的优化问题。然后指定一个初始点并求解。求解器的类型是根据变量,目标和约束的类型自动选择的,从而使您不需要了解许多可用的求解器。
This video shows how to set up and solve a constrained nonlinear optimization problem in MATLAB®。在此示例中,目标是最大程度地减少受以下约束的多变量目标函数。绘制目标函数和约束。轮廓线显示目标函数。可行区域在蓝色椭圆形内,在红色曲线下方。
这是一个非线性优化问题。在MATLAB中解决非线性优化问题有两种方法:使用基于问题的方法或基于求解器的方法。本示例使用基于问题的方法,该方法使用优化变量来定义目标和约束。有关基于求解器的方法,请参见文档。
通过这种方法解决非线性问题有共同的步骤。首先,您设置问题,定义优化变量,定义目标函数和约束,并解决问题。
Now that we have expressed the problem mathematically, we need to express the problem in MATLAB. Create an empty optimization problem container. The optimization problem holds the problem information, including the objective function and constraints.
接下来,我们将定义优化变量。通常,优化变量可以是标量,向量,矩阵或N-D数组。此示例使用变量X和Y,是标量。为此问题创建标量优化变量。在变量上包括边界。
接下来,我们将为目标函数创建优化表达式。当前,优化表达式不支持指数,因此将其写入标准MATLAB函数。金宝app要在基于问题的方法中使用此目标函数,您必须使用转换功能,从而创建优化表达式。目标函数的文件名与 @ at“ art”符号传递,该符号会创建“函数句柄”。这告诉MATLAB识别或“指向”该函数,但不要像MATLAB一样执行该函数,而MATLAB通常会在没有符号的情况下执行。现在,将目标函数添加到优化问题中。现在,该问题显示了一个非空目标和相关变量。
此问题具有以下非线性约束。第一个是解决方案位于椭圆中的约束。您可以在编写时定义此约束,并将其添加到问题中。先前的约束是多项式不等式,可以表示为优化表达。第二个约束具有指数项,不能写为优化表达式。这也包含X和Y以外的额外参数,并包含变量a。使用输入x,y和a创建一个函数。将功能转换为优化表达式。包括在MATLAB工作区中定义的优化变量和参数A。表达不平等并将约束添加到问题上。
现在,我们将检查问题公式是否完成。优化变量,目标函数,约束和界限看起来都正确。
Before solving, we need to define an initial point. The initial values for x and y must be defined as a structure. Create a structure representing the initial point as x = -3, y = 3. Solve the problem from the initial point. In general, the exit message indicates the stopping conditions and any problems encountered during the optimization. Here, the exit message and exit flag indicate that the optimization completed successfully.
Try solving the problem from a different initial point. Request additional outputs about the solution. The optimization again completed successfully but converged to a different solution. This has a higher objective function value than the first, which indicates this solution is not as good.
将解决方案点添加到可视化中。该图表明,一个解决方案位于椭圆的边界上,另一个解决方案位于指数约束和椭圆的边界上。
This video illustrated solving a constrained nonlinear optimization problem. See the documentation for additional examples.
Related Products
Learn More
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- 丹麦(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- Italia(意大利语)
- Luxembourg(English)
- 荷兰(English)
- 挪威(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia(English)
- India(English)
- New Zealand(English)
- 中国
- 日本Japanese(日本語)
- 한국Korean(한국어)