Euler method RLC series circuit,will loop forever

조회 수: 5 (최근 30일)
John Etkin
John Etkin 2015년 1월 18일
댓글: Star Strider 2015년 1월 18일
I am trying to integrate for the electrical current but when i run the script it keeps going forever an no plot is shown... Here is the script:
t(1)=0;
y=[0,0];
h=0;001;
tf=10;
n=(tf-t(1))/h;
for k=1:n
y(k+1,:)=y(k,:)+h*ord5(t(k),y(k,:));
t(k+1)=t(k)+h;
end
here is the ord5 function that needs to be integrated
function yd = ord4(t,y)
R=1,4;
L=0;
C=0;
Vs=5;
yd(1)=1/C*y(2);
yd(2)=(Vs-R*y(2)-y(1))/L;
end
Vs is the total circuit voltage and y(1)=Uc(the capacitor voltage) and y(2)=I(the circuit electric current).yd(1) is the derivative of Uc on time and yd(2) is the derivative of I on time.

채택된 답변

Star Strider
Star Strider 2015년 1월 18일
I haven’t run your code yet, but I see one problem straight away:
h=0;001;
I’m not certain what you intend, but here ‘h=0’, so ‘n=Inf’.
Might this be typo?
You may instead want:
h = 0.001;

추가 답변 (2개)

John Etkin
John Etkin 2015년 1월 18일
Thats a typing error but thats not the problem. Odd is when i run another version of Euler's method it works fine
clear all;close all;
x=[0 0];
h=0.01;
t0=0;
tf=10;
t(1)=0;
i=1;
for m=0.1:h:tf,
x(i+1,:)=x(i,:)+h* func(t,x(i,:));
t(i+1)=m;
i=i+1;
end
This one works fine,but i like the first one better cause its easier to memorize. Also,any reason why my plot is so small ?I have to give 10x the values that my teacher uses to get to see the plot else its just a small dot..

John Etkin
John Etkin 2015년 1월 18일
Thanks ,found the error i used , instead of .
  댓글 수: 1
Star Strider
Star Strider 2015년 1월 18일
My pleasure!
I didn’t see it in the code you posted, but so long as you found the error, great!
I did see:
R=1,4;
but since the comma is a legitimate decimal separator in other locations (not mine), I ignored it. (That assigns ‘R=1’ where I am.)

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

카테고리

Help CenterFile Exchange에서 Electromechanical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by