Error Code Implicit Euler Method

2 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by