Difference between fsurf and ezsurf
显示 更早的评论
I have a problem with fsurf command:
When I use
fsurf(@(x,y) ackleyfcn([x,y]),[-32 32 -32 32])
I got this warning:
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.
And this picture (after a long time, about 20 sec):

When I use
ezsurf(@(x,y) ackleyfcn([x,y]),[-32 32 -32 32])
I got no warning and the correct (and fast) picture:

Where:
function z = ackleyfcn(xx)
% Ackley's function
% Search domain: [-32,32]
% Global minimum: f(x) = 0 | x = (0,...,0)
d = size(xx, 2);
xx = max(-32,min(32,xx));
z = -20*exp(-0.2*sqrt(1/d*sum(xx.^2,2))) - exp(1/d*sum(cos(2*pi*xx),2)) + 20 + exp(1);
end
I think this Ackley's function is correctly vectorized. Am I right?
What is the error with fsurf and why the image generated by it is strange and takes longer to be generated?
Thanks in advance!
Ps.: I am using R2017b version.
采纳的回答
更多回答(1 个)
Walter Roberson
2018-3-5
0 个投票
"I think this Ackley's function is correctly vectorized. Am I right?"
No.
"Specify a function of the form z = f(x,y). The function must accept two matrix input arguments and return a matrix output argument of the same size. "
With your use of @(x,y) ackleyfcn([x,y]) the two inputs are being slammed together into the same array. You then use the width of that joined array as part of the computations. The result is going to be different for any given point than if a single point pair had been evaluated, and the results would be different if fsurf had happened to pass in a row vector of values for x and y compared to if it had happened to pass in a column vector of the same values.
类别
在 帮助中心 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!