Error using fsurf (too many functions) but success using ezsurf

10 ビュー (過去 30 日間)
Austin Vander Linden
Austin Vander Linden 2019 年 11 月 22 日
コメント済み: Walter Roberson 2023 年 1 月 7 日
When using the fsurf command to plot this function, I recieve the message: "error using fsurf, too many functions."
By simply changing "fsurf" to "ezsurf" I successfully get my 4 figures (intended to model tumors).
I understand there is a difference in the plotting methods of fsurf and ezsurf, and I assume that fsurf, if correctly used, would give me more detailed figures. What could be causing the discrepancy? I appreciate any and all help!
syms u v
for a = 3:4
for b = 5:6
figure
fsurf((1+1/5*sin(a*u)*sin(b*v))*sin(v)*cos(u),(1+1/5*sin(a*u)*sin(b*v))*sin(v)*sin(u),(1+1/5*sin(a*u)*sin(b*v))*cos(v),[0 2*pi 0 pi])
end
end

採用された回答

madhan ravi
madhan ravi 2019 年 11 月 22 日
編集済み: madhan ravi 2019 年 11 月 22 日
Just vectorize the function and use function handles. To learn the proper usage of the functions that get you into a dilemma is to read the documentation page of the function.
fsurf(@(u,v)(1+1/5*sin(a*u).*sin(b*v)).*sin(v).*cos(u),(1+1/5*sin(a*u).*sin(b*v)).*sin(v).*sin(u),(1+1/5*sin(a*u).*sin(b*v)).*cos(v),[0 2*pi 0 pi]) % just alter your line to this line
doc fsurf % to open the documentation of the function
However I'm not getting the same error message that you're getting and it's not familiar.
  2 件のコメント
Austin Vander Linden
Austin Vander Linden 2019 年 11 月 22 日
I appreciate the help, however I'm still getting the same error.
Austin Vander Linden
Austin Vander Linden 2019 年 11 月 22 日
Update- I opened a fresh instance of matlab and the command works perfectly. I'm unsure what was causing the error message, but I'm fine now. Thank you !

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

その他の回答 (1 件)

Balu
Balu 2023 年 1 月 5 日
Convert your interval argument to a double
fsurf(f, double(plot_range))
MATLAB doesn't always evaluate the final values of expressions. For example, you used 2*pi in your code. This has to be evaluated to 6.28. But if MATLAB finds it suitable, it can decide to just leave it as 2*pi and evaluate later when needed. But when your expressions are not evaluated, I think your plot range is considered a vector function. By doing double(plot_range), you get a scalar array, which is what fsurf needs.
  4 件のコメント
Balu
Balu 2023 年 1 月 7 日
編集済み: Balu 2023 年 1 月 7 日
@WalterRoberson I'd expect that to be the case for any programming language, but it doesn't appear that MATLAB is rigorous enough to do that.
When I have a range matrix of unevaluated expressions, I find that the double function is necessary to avoid the too many functions error from fsurf.
>> plot_range
[-pi/20, (11*pi)/20, -5, 5]
>> f
f =
sin(x)^20
>> fsurf(f, plot_range)
Error using fsurf
Too many functions.
>> fsurf(f, double(plot_range))
>>
MATLAB version: 9.13.0.2145394 (R2022b) Update 3
Walter Roberson
Walter Roberson 2023 年 1 月 7 日
Ah, what is going on there is that you have defined your plot_range symbolically (you are getting symbolic π there), and your f is symbolic as well. Your fsurf(f,plot_range) is then passing two symbolic expressions to fsurf(), which is only expecting one symbolic expression. The range does need to be numeric (not symbolic) for fsurf(). But this has nothing to do with "vector function" or "scalar array".

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

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by