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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by