Why is my code returning a empty row vector?
Show older comments
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
Answers (1)
Walter Roberson
on 4 Oct 2019
0 votes
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 Comments
Lia Visentin
on 4 Oct 2019
Walter Roberson
on 4 Oct 2019
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
on 4 Oct 2019
Categories
Find more on Whos 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!