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,Tx/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
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)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.