finding solution to two variable function
13 views (last 30 days)
Show older comments
i am trying to compute the critical point of my function using partial derrivatives
syms x
syms y
f=@(x,y) x*log(x*y)-y;
fpx=@(x,y) diff(f(x,y),x);
fpy=@(x,y) diff(f(x,y),y);
crit_x = solve(fpx(x,y));
crit_y = solve(fpy(x,y));
2 Comments
Star Strider
on 31 Oct 2022
What seems to be the problem?
syms x
syms y
f=@(x,y) x*log(x*y)-y;
fpx=@(x,y) diff(f(x,y),x);
fpy=@(x,y) diff(f(x,y),y);
crit_x = solve(fpx(x,y))
crit_y = solve(fpy(x,y))
.
Dyuman Joshi
on 31 Oct 2022
@Star Strider, wouldn't it be better to not use function handles with syms?
And make symbolic function like this, if syms is to be used already?
syms f(x,y)
f(x,y)=x*log(x*y)-y;
fpx=diff(f,x);
fpy=diff(f,y);
critx=solve(fpx)
crity=solve(fpy)
Answers (1)
Walter Roberson
on 31 Oct 2022
When you solve() a set of equations of multiple variables without specifying which variables to solve for, MATLAB automatically chooses which variables to solve for, preferring first x then y then z and then the rest of the alphabet. So in both cases MATLAB automatically selected x to solve for. But you wanted to solve one of them for y.
You need to decide which kind of critical point you are searching for. A point (or line) might be critical in one direction but possibly not in another, or might be a different kind of critical. x^2 - y^2 for example has maxima for one direction but minima for a different direction.
If you are looking simultaneous critical points then you cannot always get that (at least in real) if there are interactions between the variables. But if you want to try then you would ask to solve the two derivatives simultaneously
0 Comments
See Also
Categories
Find more on Symbolic Variables, Expressions, Functions, and Settings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!