MATLAB 中递归函数的积分

发布于 2024-12-18 05:14:09 字数 507 浏览 7 评论 0原文

我想计算以下递归符号积分:

function [y] = myfunc(i,T) 
    s = sym('s');
    x= sym('x');
    h=[....]  %matrix n*n (function of x)
    d=[....]  %matrix n*1 (constants)
    for k=1:n
        if (T>0)
           y= int(exp(-s*x)*h(i,k)*myfunc(k,T-x/d(i)),'x',0,T); 
    end
end

我期望 MATLAB 在计算积分时针对从 0 到 'x' 的不同值调用 myfunc(k,Tx/d(i)) T. 但是,它会返回错误,因为将使用符号值“x”而不是实际值来调用 myfunc。事实上,它无法确定if (T>0)表达式是真还是假。

如果您能建议如何计算这个递归积分,我将不胜感激。谢谢

I want to compute the following symbolic integral which is recursive :

function [y] = myfunc(i,T) 
    s = sym('s');
    x= sym('x');
    h=[....]  %matrix n*n (function of x)
    d=[....]  %matrix n*1 (constants)
    for k=1:n
        if (T>0)
           y= int(exp(-s*x)*h(i,k)*myfunc(k,T-x/d(i)),'x',0,T); 
    end
end

I expected MATLAB, while computing the integral, calls myfunc(k,T-x/d(i)) for different values of 'x' from 0 to T. However, it returns error since myfunc would be called with symbolic value 'x' and not the real value. Indeed, it cannot determine if (T>0) expression is true or false.

I would be thankful if you can suggest how this recursive integral can be computed ?. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熟人话多 2024-12-25 05:14:10

如果您想确保在递归函数的每个步骤中使用不同的实际值,您可以定义一个变量来说明递归函数的深度。

假设我们将其称为深度,并且在顶层它等于 1。每深入一步,深度就会增加 1。

现在,如果您想要获取与正确深度对应的数字,您可以将其称为y(深度)

If you want to ensure that a different real value is used in each step of a recursive function, you can define a variable to account for how deep you are.

Suppose we call it depth, and on the top level it is equal to 1. Each time you go one step deeper you increase depth by 1.

Now, if you want to get a number corresponding to the right depth, you can just call it as y(depth).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文