# Problem using 'integral' when an endpoint is the target variable for an enclosing integral

3 views (last 30 days)
Brian Dillon on 7 Nov 2019
Commented: Brian Dillon on 12 Nov 2019
I am trying to evaluate an integral over a function that includes another integral. The target variable for the outside integral is an endpoint of the inside integral. Here are the key pieces of code:
exp1 = @(ca,ma,sa) ca.*normpdf(ca,ma,sa);
exp2 = @(c1b,m2b,s2b) c1b.*normcdf(c1b,m2b,s2b) + integral(@(ca)exp1(ca,m2b,s2b),c1b,100);
EU_prior = (integral(@(c1b) exp2(c1b,mu2,sig2a),-100,c1b_pr)-s2)*normcdf(c1b_pr,mu1,sig1);
As far as I can tell, the problem is that c1b is an endpoint of the integral in exp2.
The primary error is "Error using integral (line 85) A and B must be floating-point scalars."
Thanks in advance for any help.
Brian

Walter Roberson on 12 Nov 2019
By default integral evaluates the function passing in a vector of values. You are taking that vector and passing it in as the bounds of the inner integral, but bounds must be scalar.
You can get around this by using the 'arrayvalued' option of integral() which will trigger passing in only one value at a time.
##### 1 CommentShowHide None
Brian Dillon on 12 Nov 2019
That did it. Thanks, I really appreciate the help.

### More Answers (1)

Kavya Vuriti on 12 Nov 2019
Hi,
The second and third input arguments to integral function must be scalars. From the code provided, I think either of the variables c1b or c1b_pr is not scalar or both the variables are not scalars. Since you are calculating normal cumulative distribution function of c1b, it must be either scalar value or array of scalar values. The error message may arise if c1b is an array of scalar values.
For more information on inputs to integral function, refer:https://www.mathworks.com/help/matlab/ref/integral.html#btbbkta-3

### Categories

Find more on Calculus in Help Center and File Exchange

R2018b

### Community Treasure Hunt

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

Start Hunting!

Translated by