Performing integral trapz-error invalid permutation index
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Roger Stafford
el 24 de Feb. de 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 comentarios
Lazaros Christoforidis
el 14 de Nov. de 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 comentarios
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!