Forward Euler oscillations in plot

3 ビュー (過去 30 日間)
Arkajyoti Chaterjee
Arkajyoti Chaterjee 2021 年 1 月 11 日
回答済み: Aashray 2025 年 6 月 26 日
The following code ought to apply the Forward/Explicit Euler method to solve the ODE and plot a graph. However it displays oscillations.
clc
syms t
S = solve((10 - (10+t)*exp(-t)) + 10*exp(-200*t) == 10, t); % Solve to get start of domain.
h = 0.01; % Step Size.
x = S:h:S+10; % Take a domain of 10 and divide into steps.
z = zeros(1,length(x)); % Pre-allocate.
z(1) = 10; % Initial Condition.
Y = @(t,r) -200*(r - (10 - (10+t)*exp(-t))) + exp(-t)*(9 + t); % Function.
for i=1:(length(x)-1) % Iteration loop.
y(i+1) = y(i) + h * Y(x(i),y(i)); % https://en.wikipedia.org/wiki/Euler_method#Informal_geometrical_description
end
plot(x,y,'-or','DisplayName','FE-code approximation');
  1 件のコメント
Arkajyoti Chaterjee
Arkajyoti Chaterjee 2021 年 1 月 11 日
Are we going into the unstable region? (See this)

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

回答 (1 件)

Aashray
Aashray 2025 年 6 月 26 日
The oscillations in the plot are due to the stiffness of the ODE. The Forward (Explicit) Euler method is conditionally stable.
  • The ODE contains the term -200*(r - ...), which is a very large negative coefficient (the stiffness).
  • In explicit Euler, the stability condition for linear ODEs like dy/dt = λy is:
Here, λ ≈ -200, so the step size should be:
You are using h = 0.01, which is exactly on the stability boundary. So, reducing h value will help reduce the oscillations.
You can compare the screenshots of plots I obtained with h=0.01 and h=0.099 respectively.
The second plot here converges and does not oscillate.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by