2

对于拉格朗日乘数等问题,您可以求解临界点。通常,您会得到一组关键点。有没有办法轻松地将原始函数映射到解决方案上,以在这些解决方案上评估/应用函数以获得函数值?

这是一些代码,最后一步是我不知道如何构建的代码:

f(x, y) := y^2 - x^2
g: 1/4 * x^2 + y^2

eq1: diff(f(x,y), x) = h * diff(g, x);
eq2: diff(f(x,y), y) = h * diff(g, y);
eq3: g = 1;

solve([eq1, eq2, eq3], [x, y, h]);
# Get:
# [[x=-2,y=0,h=-4],[x=2,y=0,h=-4],[x=0,y=-1,h=1],[x=0,y=1,h=1]]

# How can I get the list of values by applying the function to the
# list of solutions?
map(apply(f(x, y)), solve([eq1, eq2, eq3], [x, y, h]));

# Want (evaluated):
# [f(-2, 0), f(2, 0), f(0,-1), f(0, 1)]
# ???
4

1 回答 1

2

一种方法是将解决方案替换为函数返回的表达式。像这样的东西(我没有尝试过):

mysolutions: solve (...);
map (lambda ([solution1], subst (solution1, f(x, y))), mysolutions);
于 2021-02-20T02:04:54.387 回答