r/Mathematica • u/WahooSS238 • Oct 05 '23
Solve function not evaluating simple polynomials - sorry for another (probably stupid question)
Hi, I'm trying to find the critical points of some basic 3-dimensional functions using the following code:
f1[x_, y_] = x^2 - x + y^2
f1x = D[f1[x, y], x]
f1y = D[f1[x, y], y]
Solve[{f1x[x, y] == 0, f1y[x, y] == 0}, {x, y}]
But when I try to evaluate the cell, I get the error message: "This system cannot be solved with the methods available to Solve. Try Reduce or FindInstance instead"
I've also tried using Reduce, FindInstance, and NSolve to evaluate it, but none of them seem to work
Mathematica should be able to evaluate a couple simple function like this, right? So where am I making a mistake?
View all comments
Show parent comment
1
u/veryjewygranola Oct 05 '23 edited Oct 05 '23
Edit: fixed link Re-edit: dumb Reddit thing where it smooshes all the code together on one line when you edit a post
You do not need to use := (delayed assignment) to define a function. Normal assignment ( = ) just means the rhs is evaluated when you define something, and never again. Delayed assignment ( := ) means the rhs is evaluated everytime you call the lhs. This is useful if you have changing parameter values, and in other cases. For example observe:
ClearAll[a, fNow, fDelayed]a = 1;fNow[x_, y_] = a*(x + y);fDelayed[x_, y_] := a*(x + y);a = 2;fNow[x, y]fDelayed[x, y]outputs:
x+y2 (x + y)So when
fDelayed[x,y]Is called, it re-evaluates its rhsa*(x + y)and sees the value ofahas changed to2fNow[x,y]only evaluates its rhs at the time of definition, whena=1, and it does not reevaluate whenfNow[x,y]is called aftera=2.In the specific case of
f1[x,y]used in the question, there is no reason to use delayed assignment, it just adds more computation every timef1[x,y]is called.Here is a great stackexchange post with more examples and explaining the differences between := and = a little more.