invalid permutation index trapz

조회 수: 7 (최근 30일)
Gloust
Gloust 2014년 3월 14일
댓글: Walter Roberson 2014년 3월 15일
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.

답변 (1개)

Walter Roberson
Walter Roberson 2014년 3월 15일
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
Gloust
Gloust 2014년 3월 15일
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 2014년 3월 15일
try trapz(x, y, 2)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by