MATLAB: Error using integral (line 85) A and B must be floating-point scalars.

integral

My code is:
b=10;a=3;q=0.1;
scdf = @(x) (1-(b./(x+b)).^a)./(1-(b./(10+b)).^a);
integral(@(x) (1+q).*(1-scdf(x)).^0.5,0,10);
psi = @(p) integral(@(x) (1-scdf(x)).^0.5,0,10)-p./(1+q)-integral(@(x) (1-scdf(x)).^0.5,0,3-p);
p=0:0.001:3;
plot(p,psi(p))
The error is:
Error using integral (line 85)
A and B must be floating-point scalars.
Error in ambiguity>@(p)integral(@(x)(1-scdf(x)).^0.5,0,10)-p./(1+q)-integral(@(x)(1-scdf(x)).^0.5,0,3-p)
Error in ambiguity (line 9)
plot(p,psi(p))
Any help is very appreciated! Thanks in advance.

Best Answer

integral() function cannot accept a vector for its limits. So you cannot pass p as a vector. You will need to pass each value of p, one by one. For this, you can use arrayfun(). Try this code
b=10;a=3;q=0.1;
scdf = @(x) (1-(b./(x+b)).^a)./(1-(b./(10+b)).^a);
psi_ = @(p) integral(@(x) (1-scdf(x)).^0.5,0,10)-p./(1+q)-integral(@(x) (1-scdf(x)).^0.5,0,3-p);
psi = @(p) arrayfun(psi_, p);
p=0:0.001:3;
plot(p,psi(p))