finding solution to two variable function

16 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2022-10-31
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_x = 
crit_y = solve(fpy(x,y))
crit_y = 
y
.
Dyuman Joshi
Dyuman Joshi 2022-10-31
@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)
critx = 
crity=solve(fpy)
crity = 
y

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2022-10-31
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

类别

Help CenterFile Exchange 中查找有关 Symbolic Variables, Expressions, Functions, and Settings 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by