Reputation: 3329
For problems with, say, Lagrangian multipliers, you can solve for critical points. Often, you will get a set of critical points. Is there a way to easily map the original function over the solutions to evaluate/apply the function at those solutions to get the function values?
Here is some code with the last step being the one I can't figure out how to construct:
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)]
# ???
Upvotes: 2
Views: 390
Reputation: 17576
One way to do this is to substitute the solution into the expression returned by the function. Something like this (I didn't try it):
mysolutions: solve (...);
map (lambda ([solution1], subst (solution1, f(x, y))), mysolutions);
Upvotes: 3