Error using integral: A and B must be floating-point scalars

3 Ansichten (letzte 30 Tage)
Lena S
Lena S am 27 Mai 2017
Kommentiert: Arif Ullah khan am 30 Sep. 2018
Hey there,
I try to solve some equations where I have to use integrals. I'm not very experienced with function handles, which is where I assume to get the error.
function opt_barrier = derive_p3(beta, lambda, d)
popt = 0;
f=cell(100);
Copt=cell(100);
f0 = @(x,p) x-p+((lambda*beta*d-1)/((1-beta)*lambda));
f{1} = @(x,p) (beta*(beta + lambda*(d+(beta-1)*p)-2))/((1-beta)*lambda)+beta*x - ((1-beta)/lambda) *exp(lambda*p-lambda*x);
syms p;
syms Ctilde;
C= (beta-1)*exp(lambda*p)/lambda;
Copt{1} = C;
Vp= (lambda*beta*d-1)/((1-beta)*lambda);
p_cand=solve(exp(-lambda*(p+d))==((beta-1)^2+beta*(beta-1)^2*(-exp(-lambda*d))*(lambda*p-2))/(beta^2*(2*beta+lambda*(d+(beta-1)*p)-3)), p);
if 0 <=p_cand & p_cand <= d
popt = p_cand;
else
i=1;
while popt == 0;
integrand = @ (x,p) f{i}(x,p).*exp(lambda*x);
Copt{i+1} = @(x,p) solve(integral(@(t) integrand(t+d,p),0, p-i.*d).*exp(-lambda.*(p-i.*d))+ Ctilde == f{i}(p-i.*d, p), Ctilde);
helpfunc1 = @(x,p) exp(-lambda.*x);
intop = @(x,p) integral(@(t) integrand(t+d,p),0,x);
f{i+1} = @(x,p) intop(x,p)*helpfunc1(x,p)+ Copt{i+1}(x,p);
term= @(x,p)0;
for j=1:i
term = @(x,p) term(x,p) + integral(@(y) f{i}(y,p).*lambda.*exp(lambda.*(y-d-x)),p-j.*d, p-(j-1).*d);
end
x=p-i.*d;
helpfunc2 = @(y,p) lambda.*exp(lambda.*(y-d-x));
integrand1 = @(y,p) f{i+1}(y,p)*helpfunc2(y,p);
integrandlast = @(y,p) f0(y,p)*helpfunc2(y,p);
cand_p = solve(f{i+1}(x,p)== beta.*integral(@(y)integrand1(y,p), 0, 1) + beta.*term(x,p) + beta.*int(integrandlast,y, p, d+x), p)
popt=1;
end
end
opt_barrier=popt;
end
In the while-loop, I get the error 'Error using integral:A and B must be floating-point scalars' where I calculate p_cand, the rest is working. I assume that the integral function has problems with the 'syms' of p, but I don't know how to solve equations without using syms.
Thanks for your help!
  1 Kommentar
Arif Ullah khan
Arif Ullah khan am 30 Sep. 2018
term = @(x,p) term(x,p) + integral(@(y) f{i}(y,p).*lambda.*exp(lambda.*(y-d-x)),p-j.*d, p-(j-1).*d);
p must be a scalar value in order to make the limits of integral scalar. but you defined it as symbolic variable
syms p;
if you are doing symbolic integration then int function will work instead of integral

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Karan Gill
Karan Gill am 5 Jun. 2017
Bearbeitet: Karan Gill am 17 Okt. 2017
To represent integration with symbolic variables, use "int" instead of "integral".

Community Treasure Hunt

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

Start Hunting!

Translated by