Plotting with multiple nested arrays issue with trapz() function.
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Alvin
le 19 Juil 2017
Commenté : Walter Roberson
le 20 Juil 2017
clear
%g = 1;
k = 0.2;
no = 0;
nm = 0;
Del = 1;
Ohm = -1;
gam = 0.2;
w = (-10:0.01:10);
g = (0:0.01:20);
xat = 1 - (1i.*(w + Del).*(2./k));
xbt = 1 - (1i.*(w - Ohm).*(2./gam));
for u=1:length(g)
C = sqrt((4.*(g(u).^2))./(k.*gam));
Ca(u) = C; %C-array
c = (2.*1i.*Ca(u))./(sqrt(gam).*(xat(u).*xbt(u)+(Ca(u).^2))); %power spectrum coefficient
ca(u)= c; %c-array
d = (2.*xat(u))./(sqrt(gam).*(xat(u).*xbt(u)+(Ca(u).^2))); %power spectrum coefficient
da(u) = d; %d-array
Sbb = (abs(ca(u)).^2).*(no+(1/2))+(abs(da(u)).^2).*(nm+(1/2)); %power spectrum
Q = ((1./(2.*pi)).*trapz(w,Sbb))-0.5; %phonon population
Qa(u) = Q; %Q-array
end
figure(1)
plot(Ca,Qa)
Greetings!
As you can see, I am trying to plot a graph of Qa versus Ca. But upon running, I got an error saying: ORDER contains an invalid permutation index. I suspect it's the trapz() function not recognizing my Sbb. Given how I am trying to store lots of arrays, they got nested inside the loop and I think I lost track of what I really needed to loop over. This is really important to me and I would appreciate any form of help!
Thank you very much in advance!
0 commentaires
Réponse acceptée
Walter Roberson
le 20 Juil 2017
When you go to trapz, you have a vector of w and a scalar fractional Sbb.
trapz can be called with two arguments in a few different ways: the second argument Sbb can be an array the same size as w; Or w and Sbb can be "compatible" sizes (e.g., Sbb could be an array and w could be a vector with the same number of elements as the number of rows in Sbb); Or Sbb can be positive integer scalar that indicates the dimension number of w to work over. You are passing in a scalar so it thinks you are trying to pass a dimension number, but the dimension number you are providing is not a positive integer, so you get an error.
Perhaps you should be building an array of Sbb values, and then have your trapz after the loop ?
2 commentaires
Walter Roberson
le 20 Juil 2017
Perhaps
Q = ((1./(2.*pi)).*cumtrapz(w,Sbba))-0.5; %phonon population
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!