How to plot 3D surface with vector-input function?

2 ビュー (過去 30 日間)
ejk
ejk 2020 年 8 月 6 日
コメント済み: Star Strider 2020 年 8 月 7 日
I have a function that takes array inputs as arguments.
FUN = @(x) = x(1).^2+x(2).^2
When I try to use fsurf (ie. fsurf(FUN) or fsurf(FUN,[0 100 0 100])), the surface will not plot, and an error will appear (Error updating FunctionSurface).
surf or meshgrid don't work either.
What can I do to have this function plot, instead of un-vectorizing the handle (ie. FUN = @(x1,x2) x1.^2+x2.^2)?

採用された回答

Star Strider
Star Strider 2020 年 8 月 6 日
The function you coded:
FUN = @(x) = x(1).^2+x(2).^2;
will only take the first 2 elements of ‘x’ (whatever it is), and will return a scalar.
You need to restate it as:
FUN = @(x1,x2) x1.^2+x2.^2;
for example, to produce a surface:
[X1,X2] = meshgrid(-1:0.5:1);
figure
surf(X1, X2, FUN(X1,X2))
grid on
.
  2 件のコメント
ejk
ejk 2020 年 8 月 7 日
I take it that there's no way to do this without restating the function with two separate variables?
Star Strider
Star Strider 2020 年 8 月 7 日
That is correct.
I could not devise a way to do it otherwise, and I doubt that one exists.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by