invalid permutation index trapz

2 visualizaciones (últimos 30 días)
Gloust
Gloust el 14 de Mzo. de 2014
Comentada: Walter Roberson el 15 de Mzo. de 2014
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.

Respuestas (1)

Walter Roberson
Walter Roberson el 15 de Mzo. de 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 comentarios
Gloust
Gloust el 15 de Mzo. de 2014
Thank you for your kind response. It does not work. For one, when x==0, y=.0027, not naught. But even so, when I do add in the dimension, it errors 'LENGTH(X) must equal the length of the DIM'th dimension of Y.' This would seem to be the case since length(x)=1 and DIM=1, but in vain.
Walter Roberson
Walter Roberson el 15 de Mzo. de 2014
try trapz(x, y, 2)

Iniciar sesión para comentar.

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by