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

10 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Surface 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