MATLAB 中递归函数的积分
我想计算以下递归符号积分:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想确保在递归函数的每个步骤中使用不同的实际值,您可以定义一个变量来说明递归函数的深度。
假设我们将其称为
深度
,并且在顶层它等于 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 increasedepth
by 1.Now, if you want to get a number corresponding to the right depth, you can just call it as
y(depth)
.