invalid permutation index trapz
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would appreciate help on this. When I run the following:
tAU_e=zeros(1,1000);
%iconism II;
z=linspace(0,15,1000);
zz=num2cell(z);
secondz=1:1000;
secondzz=num2cell(secondz);
scalefactor_z= containers.Map(zz,secondzz);
for z=linspace(0,15,1000);
x=0:15/1000:z;
y=Thom_Te*c*n_e0*(1+x).^3*1.5*4.4e17.*(1+x).^(-5/2).*Q_HII(1,1:scalefactor_z(z));
tAU_e(1,scalefactor_z(z)) = trapz(x,y);
end
I retrieve the message
??? Error using ==> permute
ORDER contains an invalid permutation index
Error in ==> trapz at 44
y = permute(y,perm);
Error in ==> kSZ_numerical at 35
tAU_e(1,scalefactor_z(z)) = trapz(x,y);
I do not know how to configure this problem.
0 commentaires
Réponses (1)
Walter Roberson
le 15 Mar 2014
There are two trapz() syntaxes that allow passing in two parameters to trapz.
The first one is obvious in the documentation and is
trapz(X, Y)
where X is a scalar or vector spacing increment for the data in Y.
The second is not obvious in the documentation but can be found once you know what to look for. It is
trapz(Y, dim)
where dim is the dimension number to operate along.
In the first iteration of your "for z" loop, z is initialized to 0. Then x=0:15/100:z is 0:15/100:0 which is the scalar 0. Scalar 0 in hand for x results in scalar y of 0. So the call trapz(x, y) is a call to trapz(0,0) .
The error message suggests that this call trapz(0,0) is being interpreted as the second syntax, trapz(Y, dim), and that trapz() then errors out when it discovers that the dim of 0 is not a valid dimension number.
You can avoid this problem by passing in three parameters to trapz(), such as
trapz(x, y, 1)
2 commentaires
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!