Hello, I am trying to model a first order ODE using Euler's Method. I have shown the Euler's step in the code below and I wanted somebody to double-check it and see if it is written correctly. All the R,C,L, Ron values are given. Thankx for the help
h = 0.0001; % Adjustable time-step
t = 0:h:0.002;
for i = 1:length(t)-1
switch (switch_state)
case 1
k11 = x2(i)*1/L - x1(i)*1/(R*C);
k12 = x2(i)*-Ron/L - x1(i)*1/L + Vi*1/L;
otherwise
k11 = x2(i)*1/L - x1(i)*1/(R*C);
k12 = x2(i)*-Ron/L - x1(i)*1/L;
end
x1(i+1) = x1(i) + h*k11;
x2(i+1) = x2(i) + h*k12;
end
plot(t,x1)
plot(t,x2)

 채택된 답변

Iain
Iain 2013년 6월 3일

0 개 추천

You've implemented euler's method correctly. Whether or not you have calculated k11 and k12 correctly, and chosen sensible values for h, and LCR is another question.

댓글 수: 4

Thierry Kayiranga
Thierry Kayiranga 2013년 6월 3일
I am retracing my steps and reviewing every single part. Thankx for the help
Hello, I have an additional question. Instead of using equation form, would this matrix form of the Euler's be correct? Assuming A and B were calculated correctly. Thankx for your help again.
for j=1:f
switch (switch_state)
case 1
A = [ -Ron/L -1/L
1/C -1/(R*C)];
B = [ 1/L
0 ];
otherwise
A = [ -Ron/L -1/L
1/C -1/(R*C)];
B = [ 0
0 ];
end
for i = 1:length(t)-1
k1 = A*x(:,i) + B*Vi;
x(:,i+1) = x(:,i) + h*k1;
end
end
plot(x(1,:))
plot(x(2,:))
Iain
Iain 2013년 6월 5일
편집: Iain 2013년 6월 5일
They're not the same equations.
Remember, matrix multiplication is Row times column
But, yes, the euler implementation is correct providing that k1 is the differential of x.
Thierry Kayiranga
Thierry Kayiranga 2013년 6월 6일
Right. Row times column. Correct me if I'm wrong. So basically, the loop would take each row of A and multiply it by the corresponding column of x and add it B*Vi. And k1 would be [k11 k12]' from the earlier code. right?

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by