0

我尝试在 Matlab 中获得两个函数句柄的积分。第一个函数句柄是威布尔概率密度函数,第二个函数句柄基于我用单点线性插值创建的 cfit。

x = 0:0.1:35;
fun1 = @(x) wblpdf(x,weibullAlpha,weibullBeta);
fun2 = @(x) feval(cfitObject,x);
fun3 = @(x) (fun(x).*fun2(x));
y = integral(fun3,0,35); % Using quad(fun3,0,35) doesn't work either.

我收到以下错误:

Error using integralCalc/finalInputChecks (line 515)
Output of the function must be the same size as the input. If FUN is an array-valued  integrand,
set the 'ArrayValued' option to true.

Error in integralCalc/iterateScalarValued (line 315)
            finalInputChecks(x,fx);

Error in integralCalc/vadapt (line 132)
        [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);

Error in integralCalc (line 75)
    [q,errbnd] = vadapt(@AtoBInvTransform,interval);

Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);

Error in test (line 7) % "test" is the name of the script file.
y = integral(fun3,0,35);

问题必须与“fun2”有关,因为代码可以正常工作,例如

fun2 = x.^2;

注意:如果我用 cfitObject 绘制 fun2 ,我不会得到错误。也可以使用 quad() 来集成该函数。

x = 0:0.1:35;
fun2 = @(x) feval(cfitObject,x);
y = quad(fun2,0,35);
plot(x, fun2(x))

任何帮助是极大的赞赏!

4

1 回答 1

0

你的代码似乎没问题。可能问题是fun2不能接受向量化输入,可以通过修改fun2( cfitObject) 来处理向量输入或告诉软件积分中的函数是数组值来解决:

y = integral(fun3, 0, 35, 'ArrayValued', 1);
于 2014-11-08T13:38:38.497 回答