Plot function handle with vector input

Hi guys
This is the first question I ask in this forum. Please bear with me.
I want to make a surface plot of the following function, but I get no output:
fsurf(@(x)(x(1)^2+x(2)^2-x(1)*x(2)))
if I however use the function with standard x,y coordinates MATLAB easily makes the surface plot:
@(x,y)(x^2+y^2-x*y)
So the question is how do I make the surface plot where the input variables comes in vector form?

 採用された回答

Stephen23
Stephen23 2020 年 4 月 17 日
編集済み: Stephen23 2020 年 4 月 17 日

0 投票

newfun = @(x,y)yourfun([x,y]);
fsurf(newfun)
Could be generalized for any number of inputs:
newfun = @(varargin)yourfun([varargin{:}]);

1 件のコメント

Anders Overgaard
Anders Overgaard 2020 年 4 月 17 日
Thank you for your quick reply - solution works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by