【问题标题】:How do I create function handle from cfit, multiply with other function handle and integrate the term?如何从 cfit 创建函数句柄,与其他函数句柄相乘并整合该术语?
【发布时间】:2014-11-08 13:08:51
【问题描述】:

我尝试在 Matlab 中获取两个函数句柄的积分。第一个函数句柄是 weibull 概率密度函数,第二个函数句柄基于我使用单点线性插值创建的 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))

非常感谢任何帮助!

【问题讨论】:

  • 你试过y = integral(fun3,0,35, 'ArrayValued', 1);吗?

标签: matlab integration curve-fitting function-handle


【解决方案1】:

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

y = integral(fun3, 0, 35, 'ArrayValued', 1);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 1970-01-01
    • 1970-01-01
    • 2015-06-29
    • 1970-01-01
    • 2018-10-30
    相关资源
    最近更新 更多