Why is my code returning a empty row vector?
이전 댓글 표시
function[t,i]=RLSolver(R,L,T,Vs,i0,dt)
t=0:dt:T;
i=zeros(1,length(t));
i(1)=i0;
for j=1:length(t)-1
i(j+1)=(dt/L)*(Vs-R*i(j))+i(j);
end
답변 (1개)
Walter Roberson
2019년 10월 4일
0 개 추천
What values are you passing in for the third (T) and 6th (dt) parameters?
I think you will find that your third parameter T is less than 0 so 0:dt:T is empty.
댓글 수: 3
Lia Visentin
2019년 10월 4일
Walter Roberson
2019년 10월 4일
You cannot run that code by simply pressing the green Run button. You have to either go down to the command line and type in a command such as
RLSolver(3,8,2.1,11.9,2.7,0.1)
or else you have to have a function or script that does something similar. In the example, the 3, 8, 2.1, and so on, are values being passed in for R, L, and T respectively.
If you passed in 0 for the third parameter then t=0:.1:0 and that should be valid giving you the scalar t=0 and you would get a scalar output for i . If you are getting an empty result for t, then it is because the real component of the third value you are passing in is negative.
Lia Visentin
2019년 10월 4일
카테고리
도움말 센터 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!