"Unable to compute number of steps from 0 to n by 1" error for symbolic integration
Show older comments
Im trying to do numerical integration with the following function that have several parameters. My issue is that whenever I assign n as symbolic symbol, I got the error "Unable to compute number of steps from 0 to n by 1". I Also tried using symsum instead of arrayfunc and I got the same error.
n=60;
syms u_f positive
syms lam_f positive
syms z positive
syms alpha positive
syms sigma positive
syms ep positive
syms z positive
syms b positive
syms d positive
assume (ep <1 & ep>0)
%assume(z < u_f )
%syms n
% assume (n, {'postive', 'integer'})
nCk = @(n,kVec,z)arrayfun(@(k)lam_f*exp(-lam_f*(alpha-b)).*(nchoosek(n,k)*(1*ep).^(k).*((1-ep)*(0.5+0.5*erf((z-u_f-d)/(sqrt(2)*sigma)))).^(n-(k)).*(0.5+0.5*erf((z-alpha-u_f-d)/(sqrt(2)*sigma)))^k),kVec);
%F(z,u_f,lam_f,sigma,ep)=int(nCk(n,0:n,z),alpha,0, z);
F(z,u_f,lam_f,sigma,ep,b,d)=vpaintegral(nCk(n,0:n,z),alpha,b, z);
result=vpaintegral( 1-sum(vpa(F(z,0.4,7.1111,0.009,0.1,2,2))),0,Inf,'ArrayValued',true,'RelTol', 1e-5, 'AbsTol', 1e-4)
My end goal is writing a user defined function like the following:
function result=norm_expo_gang_function_mean_handle(n,uu,lamm,oo,epp,bb,dd)
%(u,lam,o,b,d,ep,sz1,sz2)
syms F(z,u_f,lam_f,sigma_o,b,d,ep)
syms u_f positive
syms lam_f positive
syms z positive
syms alpha_o positive
syms sigma_o positive
syms ep positive
syms z positive
syms b positive
syms d positive
assume (ep <1 & ep>0)
assume(z,'positive')
assume(lam_f,'positive');
assume(u_f,'positive');
assume(sigma_o,'positive');
assume(b,'positive');
assume(d,'positive');
%assume(n,{'positive','integer'});
assume (ep <1 & ep>0)
nCk = @(n,kVec,z)arrayfun(@(k)lam_f*exp(-lam_f*(alpha-b)).*(nchoosek(n,k)*(1*ep).^(k).*((1-ep)*(0.5+0.5*erf((z-u_f-d)/(sqrt(2)*sigma)))).^(n-(k)).*(0.5+0.5*erf((z-alpha-u_f-d)/(sqrt(2)*sigma)))^k),kVec);
%nCk = @(n,kVec,z)arrayfun(@(k)lam_f*exp(-lam_f*(alpha-b)).*(nchoosek(n,k)*(1*ep).^(k).*((1-ep)*(0.5+0.5*erf((z-u_f-d)/(sqrt(2)*sigma)))).^(n-(k)).*(0.5+0.5*erf((z-alpha-u_f-d)/(sqrt(2)*sigma)))^k),kVec);
%F(z,u_f,lam_f,sigma,ep)=int(nCk(n,0:n,z),alpha,0, z);
F(z,u_f,lam_f,sigma_o,ep,b,d)=vpaintegral(nCk(n,0:n,z),alpha,b, z);
result=vpaintegral( 1-sum(vpa(F(z,uu,lamm,oo,epp,bb,dd,n))),0,Inf,'ArrayValued',true,'RelTol', 1e-5, 'AbsTol', 1e-4);
%F(z,u_f,lam_f,sigma_o,b,d,ep,n) = @(n,kVec,z)arrayfun(@(k)lam_f*exp(-lam_f*(alpha_o-b)).*(nchoosek(n,k)*(1*ep).^(k).*((1-ep)*(0.5+0.5*erf((z-u_f-d)/(sqrt(2)*sigma_o)))).^(n-(k)).*(0.5+0.5*erf((z-alpha_o-u_f-d)/(sqrt(2)*sigma_o)))^k),kVec);
end
Answers (1)
Walter Roberson
on 20 Sep 2024
syms z positive
syms b positive
%...
F(z,u_f,lam_f,sigma,ep,b,d)=vpaintegral(nCk(n,0:n,z),alpha,b, z);
You are trying to vpaintegral() with a symbolic lower and upper bound. When you vpaintegral() the bounds must be definite numbers
8 Comments
Walter Roberson
on 20 Sep 2024
Edited: Walter Roberson
on 20 Sep 2024
Q = @(v) sym(v);
n=60;
syms u_f positive
syms lam_f positive
syms z positive
syms alpha positive
syms sigma positive
syms ep positive
syms z positive
syms b positive
syms d positive
assume (ep <1 & ep>0)
%assume(z < u_f )
%syms n
% assume (n, {'postive', 'integer'})
nCk = @(n,kVec,z)arrayfun(@(k)lam_f*exp(-lam_f*(alpha-b)).*(nchoosek(n,k)*(1*ep).^(k).*((1-ep)*(0.5+0.5*erf((z-u_f-d)/(sqrt(2)*sigma)))).^(n-(k)).*(0.5+0.5*erf((z-alpha-u_f-d)/(sqrt(2)*sigma)))^k),kVec);
%F(z,u_f,lam_f,sigma,ep)=int(nCk(n,0:n,z),alpha,0, z);
F(z,u_f,lam_f,sigma,ep,b,d)=int(nCk(n,Q(0:n),z),alpha,b, z, 'hold', true)
result=int( 1-sum((F(z,Q(0.4),Q(7.1111),Q(0.009),Q(0.1),Q(2),Q(2)))),0,Inf,'hold', true)
%release(result)
the release() step times out here on MATLAB Answers.
Muna Tageldin
on 22 Sep 2024
Walter Roberson
on 22 Sep 2024
What step are you encountering the error on?
My guess at the moment is that you are using a MATLAB version that is too old to support the 'hold' option ?
Muna Tageldin
on 22 Sep 2024
Walter Roberson
on 22 Sep 2024
Edited: Walter Roberson
on 22 Sep 2024
Q = @(v) sym(v);
n=60;
syms u_f positive
syms lam_f positive
syms z positive
syms alpha positive
syms sigma positive
syms ep positive
syms z positive
syms b positive
syms d positive
assume (ep <1 & ep>0)
%assume(z < u_f )
%syms n
% assume (n, {'postive', 'integer'})
nCk = @(n,kVec,z)arrayfun(@(k)lam_f*exp(-lam_f*(alpha-b)).*(nchoosek(n,k)*(1*ep).^(k).*((1-ep)*(0.5+0.5*erf((z-u_f-d)/(sqrt(2)*sigma)))).^(n-(k)).*(0.5+0.5*erf((z-alpha-u_f-d)/(sqrt(2)*sigma)))^k),kVec);
F(z,u_f,lam_f,sigma,ep,b,d)=int(nCk(n,Q(0:n),z),alpha,b, z)
result=int( 1-sum((F(z,Q(0.4),Q(7.1111),Q(0.009),Q(0.1),Q(2),Q(2)))),0,Inf)
This will take a fair while -- roughly 5 minutes.
After that you may wish to
R = vpa(result)
Muna Tageldin
on 23 Sep 2024
Edited: Muna Tageldin
on 23 Sep 2024
Walter Roberson
on 23 Sep 2024
nested vpaintegral calls are less accurate than vpa of a complete integral.
Also you were attempting to vpaintegral with symbolic boundaries, which is not permitted
Muna Tageldin
on 24 Sep 2024
Categories
Find more on Calculus in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!