フィルターのクリア

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

2 ビュー (過去 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 Center および File ExchangeNumeric Solvers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by