# Cannot find the indefinite integral of a function with a variable limit

2 views (last 30 days)

Show older comments

I am trying to find the integral for an indefinite integral with a variable as a limit. The following variable is the limit I need to use:

k =

log((828390857088487*D)/2251799813685248 + 3675208770282009/2251799813685248)/4 - log(D + 1)/4 + 6510907742581231/9007199254740992

The function to be integrated is:

fun1= @(k)((u_h0-k(j))*chi2pdf(k(j),N))*Pram(j); (K(j) changes in a loop where the limit of integration also changes)

However, I am getting the following errors:

Error using mupadmex Error in MuPAD command: symbolic:sym:isAlways:LiteralCompare|1/2 <= log((828390857088487*D_Var)/2251799813685248 + 3675208770282009/2251799813685248)/359538626972463181545861038157804946723595395788461314546860162315465351611001926265416954644815072042240227759742786715317579537628833244985694861278948248755535786849730... [subproc]

Error in sym/subsindex (line 728) X = find(mupadmex('symobj::logical',A.s,9)) - 1;

Error in sym/subsref (line 771) R_tilde = builtin('subsref',L_tilde,Idx);

Error in gampdf>f (line 77) y(i1) = exp(-z(i1));

Error in gampdf (line 64) y(k(i)) = f(z(i),a(i)+1) .* exp(log(a(i)+1)-log(z(i))) ./ b(i);

Error in chi2pdf (line 36) y = gampdf(x,v/2,2);

Please help

##### 0 Comments

### Answers (1)

Walter Roberson
on 19 Feb 2018

gampdf is from the stats toolbox and is not defined over symbolic expressions.

In particular gampdf needs to detect negative inputs and set the results to zero there. It needs to compare the input values to 0 for that purpose. But you did not put enough assumptions on D for the symbolic engine to be able to prove that your expression is either always less than zero (in which case it would return 0) or always nonnegative (in which case the main calculation is valid). The resulting expression from the comparison is neither logical nor a nonnegative integer but is a symbolic expression instead... And symbolic expressions cannot be used as indices.

You might perhaps be able to proceed by putting enough assume() on D for the symbolic toolbox to be able to prove that the coefficients are in the range for normal calculations, but if it is possible at all it would only be in the latest version of MATLAB, as the earlier versions just give up in the situation instead of trying to use isAlways().

My recommendation is to look in the gampdf source to find the calculation under the assumption that the inputs are valid, and to use the calculation directly instead of calling gampdf so that the bounds checking giving you problems is not done.

##### 2 Comments

Walter Roberson
on 19 Feb 2018

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!