Error Code Implicit Euler Method

조회 수: 1 (최근 30일)
Ethem TEKE
Ethem TEKE 2019년 10월 22일
댓글: Vishwarajsinh Gohil 2020년 11월 22일
Hello,
I have a problem about my code. I take a error code "Error in Untitled (line 18) l(x+1)=l(x)-(((c*h)/3)*l(x+1))-16*m(x+1)*h"
How can I correct this?
Thank you from now.
clear all
c=30;
u(1)=1;
v(1)=-2;
h=0.1;
m(1)=1;
l(1)=-2;
%explicit euler
for n=1:10
u(n+1)=u(n)+(h*v(n))
v(n+1)=v(n)-(((c*h)/3)*v(n))-16*u(n)*h;
n=1:11;
end
%implicit euler
for x=1:10
m(x+1)=m(x)+(h*l(x))
l(x+1)=l(x)-(((c*h)/3)*l(x+1))-16*m(x+1)*h;
end
  댓글 수: 1
darova
darova 2019년 10월 22일
Maybe you made a mistake
321.png

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

채택된 답변

ME
ME 2019년 10월 22일
The problem in the code itself is that in
l(x+1)=l(x)-(((c*h)/3)*l(x+1))-16*m(x+1)*h;
the l(x+1) term exceeds your matrix dimension, i.e. you only have l defined up to l(x) and you are trying to use l(x+1) in the calculation.
A slightly larger problem in your question is that you have not correctly defined your implicit solution scheme. For your set of equations
(assuming I have worked that out correctly) your numerical scheme should look more like:
which will be more complicated to solve than the scheme you lay out above because you would need to know both and in advance. As such this would usually be solved using either matrix or iterative solution methods.
If instead you wanted to go for a semi-implicit method then you could simply change the l(x+1) in your code to l(x).Or a final option would be to alternate the order of your equations on each time step. That way you would alternate which variable is being calculated explicitly and which is calculated implicitly.
I hope this all helps.
  댓글 수: 1
Vishwarajsinh Gohil
Vishwarajsinh Gohil 2020년 11월 22일
can you please help with iterative solution method. How do we plugin them here?
Thanks,

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by