# 对偶问题

![](/files/-M7DeQ_piCAK35Y2FzTa)

绿线标出的是约束$$g(x,y)=c$$的点的轨迹。蓝线是$$f(x,y)$$的等高线。箭头表示斜率，和等高线的法线平行。从梯度的方向上来看，显然有$$d1 \gt d2$$。绿色的线是约束，也就是说，只要正好落在这条绿线上的点才可能是满足要求的点。如果没有这条约束，$$f(x,y)$$的最小值应该会落在最小那圈等高线内部的某一点上。而现在加上了约束，最小值点应该在哪里呢？显然应该是在f(x,y)的等高线正好和约束线相切的位置，因为如果只是相交意味着肯定还存在其它的等高线在该条等高线的内部或者外部，使得新的等高线与目标函数的交点的值更大或者更小，只有到等高线与目标函数的**曲线相切**的时候，可能取得最优值。

如果我们对约束也求梯度$$\nabla g(x,y)$$，则其梯度如图中绿色箭头所示。很容易看出来，要想让目标函数$$f(x,y)$$的等高线和约束相切，则他们切点的梯度一定在一条直线上(f和g的斜率平行)。

也即在最优化解的时候：$$\nabla f(x,y) = \lambda (\nabla g(x,y) - C)$$ , 即：$$\nabla \[f(x,y) + \lambda g(x,y) - C] = 0, \lambda \neq 0$$

[关于拉格朗日乘子法与KKT条件](<http://www.moozhi.com/topic/show/54a8a261c555c08b3d59d996 >)\
[Lagrange 是怎么想出来Lagrange乘子法的](https://www.zhihu.com/question/37137053)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://json007.gitbook.io/svm/math-convex_optimization/dui_ou_wen_ti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
