
Error using integral (line 85) A and B must be floating-point scalars.
5 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Ameer Hamza
on 11 May 2020
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))

2 Comments
More Answers (0)
See Also
Categories
Find more on Continuous in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!