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

조회 수: 3 (최근 30일)
Lena S
Lena S 2017년 5월 27일
댓글: Arif Ullah khan 2018년 9월 30일
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
Arif Ullah khan
Arif Ullah khan 2018년 9월 30일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Karan Gill
Karan Gill 2017년 6월 5일
편집: Karan Gill 2017년 10월 17일
To represent integration with symbolic variables, use "int" instead of "integral".

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by