Find the minimum of a multi-variable function
36 次查看(过去 30 天)
显示 更早的评论
Question: Find the minimum of
in the window [0,2]×[2,4] with increment 0.01 for x and y.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226011/image.png)
My approach:
syms fun(x,y) fx(x,y) fy(x,y) fxy(x,y) x y
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226012/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226013/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226014/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226015/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226016/image.png)
pt=solve([
==0,
==0],[x y]) But it gives me an error.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226017/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226018/image.png)
besides what about the window and increment mentioned that question. Any solution will be appreciated .
Thanks in advance .
2 个评论
采纳的回答
infinity
2019-6-23
编辑:infinity
2019-6-23
Hello,
In your code, it was not good to put the name like "fun(x,y)". Also, we do not need to declare "fx, fun, fy,.." as symbolic variable. Here is a small code that you can refer
clear
syms x y
fun=x^2+y^2-2*x-6*y+14;
fx=diff(fun,x);
fy=diff(fun,y);
pt=solve([fx==0,fy==0],[x y]);
% pt=solve(fx==0,fy==0);
sol = struct2array(pt)
It will give us the solution
sol =
[ 1, 3]
I have run this code on Matlab2018a. Maybe in your Matlab version, there will be some different.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!