Plotting with multiple nested arrays issue with trapz() function.
Show older comments
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!
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!