How to code a 1D ODE in MATLAB
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Torsten
am 26 Mär. 2025
Bearbeitet: Torsten
am 26 Mär. 2025
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!