Why is fsurf complaining when it plots -e^(-x^2)?

1 回表示 (過去 30 日間)
Brando Miranda
Brando Miranda 2018 年 1 月 13 日
回答済み: Star Strider 2018 年 1 月 13 日
I wanted to plot:
with fsurf however, when I tried it complained about errors, what I did was:
>> fsurf(@(x,y) -exp( -(x)^2), [-10 10 -10 10])
why does that give the following error:
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.
> In matlab.graphics.function.FunctionSurface>getFunction
In matlab.graphics.function.FunctionSurface/updateFunction
In matlab.graphics.function.FunctionSurface/set.Function
In matlab.graphics.function.FunctionSurface
In fsurf>singleFsurf (line 261)
In fsurf>@(f)singleFsurf(cax,{f},extraOpts,args) (line 227)
In fsurf>vectorizeFsurf (line 227)
In fsurf (line 200)
>>
????
the plot it gives is ugly:

回答 (1 件)

Star Strider
Star Strider 2018 年 1 月 13 日
The warnings disappear if you use element-wise operations (the ‘dot operator’ for the exponentiation), and the plot looks better if you reduce the x-range:
fsurf(@(x,y) -exp( -(x).^2), [-5 5 -10 10])

カテゴリ

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