small trapz clarification needed

2 views (last 30 days)
Gloust
Gloust on 5 Mar 2014
Edited: the cyclist on 5 Mar 2014
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 Comment
the cyclist
the cyclist on 5 Mar 2014
I deleted the duplicate of this question that you posted earlier.

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 5 Mar 2014
Edited: the cyclist on 5 Mar 2014
[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

Community Treasure Hunt

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

Start Hunting!