small trapz clarification needed
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Antworten (1)
the cyclist
am 5 Mär. 2014
Bearbeitet: the cyclist
am 5 Mär. 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!