Performing integral trapz-error invalid permutation index
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Roger Stafford
2015년 2월 24일
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
Lazaros Christoforidis
2019년 11월 14일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!