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 个)

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 个评论

T=0 and dt=0.1. What does it mean by passing in values?
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.

请先登录,再进行评论。

类别

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by