是否可以定义积分函数并使用“积分”进行积分?

时间:2017-05-19 04:57:38

标签: matlab integral

我想进行以下整合:

\int_t^T\left{(T-u)sigma_{u}-(\int_u^T\lambda(T-s)e^{-\lambda s}ds)e^{\lambda u}\right}du

为了使用matlab中的函数integral进行集成,我定义了函数

\left{(T-u)sigma_{u}-(\int_u^T\lambda(T-s)e^{-\lambda s}ds)e^{\lambda u}\right}

首先

然后应用integral。以下是我的功能:

OrderEpsilon2IntegrandIntegralIntegrand=@(T,s)lambda.*(T-s).*exp(-1.*lambda.*s);
OrderEpsilon2IntegrandIntegral=...
@(T,u)integral(@(t)OrderEpsilon2IntegrandIntegralIntegrand(T,t),u,T);

OrderEpsilon2Integrand=@(T,u)...
(T-u).*sigma(u).*v_0-...
OrderEpsilon2IntegrandIntegral(T,u).*exp(lambda.*u).*sigma(u).*v_0;

OrderEpsilon2Integral=...
@(t)arrayfun(@(T)integral(OrderEpsilon2Integrand(T,u),InitialTime,T),t);

但是,我有以下错误消息:

Error using integral (line 85)
A and B must be floating-point scalars.

Error in (T,u)integral(@(t)OrderEpsilon2IntegrandIntegralIntegrand(T,t),u,T)

Error in @(T,u)(T-u).*sigma(u).*v_0-OrderEpsilon2IntegrandIntegral(T,u).*exp(lambda.*u).*sigma(u).*v_0

Error in @(u)OrderEpsilon2Integrand(2.3,u)

Error in integralCalc/iterateScalarValued (line 314)
            fx = FUN(t);

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);

发生此类错误的问题是什么?我对这条消息没有任何想法。另外,我想知道如何纠正代码。但是,纠正代码存在一些限制:

首先,不要写

\int_u^T \lambda(T-s)e^{-\lambda s}ds)e^{\lambda u}

明确。

其次,请勿使用integral2。如果可能的话,我想定义具有积分的被积函数。

1 个答案:

答案 0 :(得分:0)

为什么不呢?:

syms s u T t sg lm
%%sg=u^2+u+1; %%Define sigma expression in here
f=int((T-u)*sg-int(lm*(T-s)*exp(-lm*s),s,u,T)*exp(lm*u),u,t,T) 

导致:

T*t + T/lm + (T^2*sg)/2 - t/lm + (sg*t^2)/2 - T^2/2 - 1/lm^2 - t^2/2 + (exp(-T*lm)*exp(lm*t))/lm^2 - T*sg*t