small trapz clarification needed

조회 수: 10 (최근 30일)
Gloust
Gloust 2014년 3월 5일
편집: the cyclist 2014년 3월 5일
I would appreciate some clarification.
I attempt the following:
zz=zeros(1,31);
for xx=linspace(0,30,31);
x=0:xx;
y=(c*56e9*3.14e7*(1+x).^2)./(1+(1+x).^2);
zz(1,xx+1)=trapz(x,y);
end
I get the following errata description:
??? Error using ==> colon
Maximum variable size allowed by the program is exceeded.
Error in ==> trapz at 43
perm = [dim:max(ndims(y),dim) 1:dim-1];
Error in ==> Cs_kSZ at 14
eta(1,xx+1)=trapz(x,y);
What is the particular problem?
  댓글 수: 1
the cyclist
the cyclist 2014년 3월 5일
I deleted the duplicate of this question that you posted earlier.

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

답변 (1개)

the cyclist
the cyclist 2014년 3월 5일
편집: the cyclist 2014년 3월 5일
[FYI, I put in c=1 to get your code to work at all.]
In the first iteration of your for loop, you are calling trapz() with these inputs:
trapz(0,8.79e17)
which is I suppose you mean to be zero (because you are "integrating" over a single point). However, MATLAB does not handle that case very well, possibly due to floating point error.
I think you might get what you want by skipping that first evaluation, using this modification of your code:
zz=zeros(1,31);
for xx=linspace(1,30,30);
x=0:xx;
y=(c*56e9*3.14e7*(1+x).^2)./(1+(1+x).^2);
zz(1,xx+1)=trapz(x,y);
end

카테고리

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