Performing integral trapz-error invalid permutation index
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the following code
Vg = linspace(0, 5, 100);
for t = 1:length(Vg);
Fun(t) =((Vg(t)^2)/(exp(Vg(t)/(k*Ts))-1));
IntNs(t) = trapz(Vg,Fun(t));
end
Every time I attempt to run this I receive the error message "Order contains an invalid permutation index", Im not quite sure what is going awry as I have run an almost identical code in other scripts. Could anyone guide me to the problem and how to correct it.
Thanks
-Jarett
0 commentaires
Réponses (2)
Roger Stafford
le 24 Fév 2015
Apparently you wish to find the integral of the function 'Fun' with respect to 'Vg'. If so, the line
IntNs(t) = trapz(Vg,Fun(t));
should be located after you have exited the for-loop:
Vg = linspace(0, 5, 100);
for t = 1:length(Vg);
Fun(t) =((Vg(t)^2)/(exp(Vg(t)/(k*Ts))-1));
end
IntNs = trapz(Vg,Fun);
As you have it, you are trying to find the integral of the scalar Fun(t) with respect to 'Vg' which 'trapz' doesn't like. See the documentation at:
http://www.mathworks.com/help/matlab/ref/trapz.html
Note where it says, "Q = trapz(X,Y) integrates Y with spacing increment X. By default, trapz operates on the first dimension of Y whose size does not equal 1. length(X) must be equal to the size of this dimension." That is obviously not true in your use of 'trapz', since Fun(t) is a scalar.
0 commentaires
Lazaros Christoforidis
le 14 Nov 2019
Hey
Im kinda late, but I think I will help others
c='number ';
basically try IntNs=cumtrapz(Vg,Fun)+c;
where c: u choose it
0 commentaires
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!