你不同意你確切的代碼,所以我不知道你做了什麼,讓只有一個解決辦法,但你可以用象徵性的工具箱來解決這個小狗:
% # Define the function f(x, y)
syms x y
f = 0.05 * (1 - 12*x + 20*x^2) * (1 - 7*y + 10*y^2) * exp(-(x^2/6 + y^2/3));
% # Find the partial derivatives
f_x = diff(f, x);
f_y = diff(f, y);
% # Find the critical points
[xcr, ycr] = solve(f_x, f_y);
p = double([xcr(:), ycr(:)]);
% # Discard the complex solutions
p(imag(p(:, 1)) > eps, :) = [];
p(imag(p(:, 2)) > eps, :) = [];
p = real(p);
xcr = p(:, 1)
ycr = p(:, 2)
這實際上產生了13解決方案:
xcr = ycr =
0.5000 0.2000
0.5000 0.5000
0.1000 0.2000
0.1000 0.5000
2.6133 1.9238
-2.3113 1.9238
0.2980 1.9238
2.6133 -1.5711
-2.3113 -1.5711
0.2980 -1.5711
2.6133 0.3474
-2.3113 0.3474
0.2980 0.3474
with surf(x,y,z)...可以看到有4個最大值,4個鞍座,也許在另外四個之間。 – user1003131