Plotting with multiple nested arrays issue with trapz() function.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2017-7-20
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 ?
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!