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
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
Lia Visentin 2019년 10월 4일
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.
Lia Visentin
Lia Visentin 2019년 10월 4일
thank you!

댓글을 달려면 로그인하십시오.

카테고리

질문:

2019년 10월 4일

댓글:

2019년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by