Fundamental issue with trapz() function (or not?)
Mostra commenti meno recenti
clear
C1 = 0;
k1 = 1;
k2 = 0;
n1 = 0;
n2 = 0;
nm = 1;
D = 0;
O = 0;
gam = 1e-04.*k1;
alph = 0;
w = linspace(-5,5,300);
TA = (w+D)./(k1./2);
TB = (w-O)./(gam/2);
xa = 1-1i*TA;
xb = 1-1i*TB;
C = (2.*1i.*sqrt(C1))./(sqrt(gam).*((xa.*xb)+C1));
D = (2.*xa)./(sqrt(gam).*((xa.*xb)+C1));
MC = (abs(C)).^2;
MD = (abs(D)).^2;
Sbb = 2.*pi*(MC.*(n1+0.5)+MD.*(nm+0.5));
A = trapz(w,Sbb)./(2.*pi);
%AA(ii)=A;
figure(1)
plot(w,Sbb);
set(gca,'FontSize',13)
xlabel('\omega')
ylabel('S_{bb}')
%xlim([0,10000])
Upon compiling the code above, one would find a curve with a very narrow width centered about 0. Furthermore, it can be seen that the area under the curve was computed using the trapz() function and stored in A (well it's divided by 2pi but that is just scaling). A = 0.0442 in this case as observed from the workspace and all is well.
However as I decrease the range of my w. Say:
w = linspace(-0.1,0.1,300);
My area would give A = 2.1705 in this case (it increased). This doesn't make sense given that the tail ends on both sides of the curve barely contributes to the area under the curve (it's a spectral density curve) since they are so small. It is implying that as my range (w) decreases, my area increases which is physically absurd. Furthermore, upon some investigation, it seems that the area would peak roughly when the range is at:
w = linspace(-8e-03,8e-03,300)
Which gives A = 9.3343. Further reducing the range would then decrease the area. Does anyone know what seems to be the issue?
Thanks in advance!
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Numerical Integration and Differentiation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!