Matlab 中匿名函数定义内的匿名函数调用

anonymous function calls within anonymous Function definitions in Matlab

我很想知道为什么这段代码不起作用。如果有人知道导致 matlab 发现这么多错误的原因,我们将不胜感激。

m = 1;
c = 1.5;
fun =@(x, epsilon) 1 .* (1 - (1 - cos(x))/(2.*epsilon)).^c .* cos(m.*x);
a = @(ep) acos(1-(2*ep));

lm =@(e) 1/(2.*pi) .* integral(@(x)fun(x, e), -1.*a(e), a(e));
fprintf('ball bearing at 0.6 is %4.4f', lm(0.6));

我要复制的函数是() =1/2∫[1 − (1 − cos())/2]^ cos()dx

据我所知,乘法不需要点修饰符,但是 Matlab 抱怨说这需要逐元素运算,即使不涉及矩阵。

根据 integral 的文档,要集成的函数必须矢量化:

For scalar-valued problems, the function y = fun(x) must accept a vector argument, x, and return a vector result, y. This generally means that fun must use array operators instead of matrix operators. For example, use .* (times) rather than * (mtimes).