How to code a 1D ODE in MATLAB

6 ビュー (過去 30 日間)
JUBAIR
JUBAIR 2025 年 3 月 26 日
コメント済み: JUBAIR 2025 年 3 月 26 日
Dear Community
I am trying to code the following 1D ODE using backward difference approximation:
dW/dt =U* (dW/dX) +C
I have entered the equation in MATLAB as below:
W(1) = some constant; Boundary condition at inlet
for i = 2:n
DWDt(i) = - U*((W(i)-W(i-1))/(X(i)-X(i-1)))+C ;
end
My question is: Although in my equation U*(dW/dX) is a positive term, why I need to use negative sign in the for loop? if I make the term U8 (dW/dX) positive in the for loop, the ODE23 command can't solve the equation.
I would highly appreciate if someone can answer.
  1 件のコメント
JUBAIR
JUBAIR 2025 年 3 月 26 日
Here U is the veloctiy term in m/s

サインインしてコメントする。

採用された回答

Torsten
Torsten 2025 年 3 月 26 日
編集済み: Torsten 2025 年 3 月 26 日
Usually, the equation reads
dW/dt + U*dW/dx = C (1)
If U in this equation is positive, your flow goes from left to right, if U is negative, your flow goes from right to left.
Depending on the sign of U in (1), you must discretize dW/dX in point X(i) as
(W(i)-W(i-1))/(X(i)-X(i-1)) if U > 0 (information comes from left)
and as
(W(i+1)-W(i))/(X(i+1)-X(i)) if U < 0 (information comes from right)
We call it "Upwind Differencing". Using a discretization that doesn't follow the physical direction of informational flow leads to an unstable discretization and thus a failure of the ODE integrator.
  1 件のコメント
JUBAIR
JUBAIR 2025 年 3 月 26 日
Thanks for the explanation. That helps a lot.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by