"Unable to compute number of steps from 0 to n by 1" error for symbolic integration
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Walter Roberson
le 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 commentaires
Walter Roberson
le 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
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!