Why is my code returning a empty row vector?
Mostrar comentarios más antiguos
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
Respuestas (1)
Walter Roberson
el 4 de Oct. de 2019
0 votos
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 comentarios
Lia Visentin
el 4 de Oct. de 2019
Walter Roberson
el 4 de Oct. de 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
el 4 de Oct. de 2019
Categorías
Más información sobre Whos en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!