Nonlinear ODE. Solve The Nonlinear ODE
Nonlinear ODE. Solve The Nonlinear ODE
Assuming you will pay attention to all FDM steps, let’s focus on the differences of the current method
with the forward Euler. Construct the discretized ODE using the implicit Euler method:
Eq. 3 is a nonlinear algebraic equation which needs to be solved by 𝑦𝑖+1 . A root finding method needs to
be used: Newton’s, secant, fixed-point, etc. Eq.3 was used to develop the matlab code in appendix.
QUICK SOLUTION. For a quick solution by hand, the first-time step (𝑖 = 0) in Eq.3:
Simplify Eq.5:
𝑦1 = 1 + 0.12 √𝑦1 ; Eq.6 and 𝑡1 = 0.1
Eq.6 is an implicit nonlinear equation, where the task at hand is to solve by 𝑦1 . Newton, secant, fixed-
point or any other root finding methods can be used.
NEWTON’S METHOD (NM). Due to its fans club, let’s start with the Newton’s method:
𝑓
𝑥𝑖+1 = 𝑥𝑖 − 𝑓′𝑖 Eq.7
𝑖
Where 𝑥𝑖+1 is the new root approximation of the function 𝑓𝑖 . This is an iterative method where the first
value of the root 𝑥𝑖 is usually extracted by inspection from a graph of 𝑓𝑖 𝑣𝑠 𝑥𝑖 .
Let’s change the variable notation of the Eq.6, so it looks more familiar (e.g., call the unknown 𝑥 = 𝑦1 ):
A plot of the Eq.9 is shown, the oval region is where the root is:
where:
𝑓𝑖 = 1 + 0.12 √𝑥𝑖 − 𝑥𝑖 Eq. 9
0.06
𝑓𝑖′ = −1 + 𝑥 Eq.10
√ 𝑖
𝑓𝑖 𝑓0 1+0.12 √𝑥𝑜−𝑥𝑜
𝑥𝑖+1 = 𝑥𝑖 − ; ==> 𝑥1 = 𝑥𝑜 − = 𝑥𝑜 − 0.06 Eq.11
𝑓𝑖′ 𝑓0′ −1+
√𝑥𝑜
NM needs an initial estimate of the root. This can be any point close to the root. The obvious is 𝑥𝑜 = 1.
Please note that this is just the initial condition 𝑦0 = 1. The new root shouldn’t be too far away this
value, then:
The problem doesn’t end here, the value of 𝑥1 = 1.12766 is not the root of Eq. 6 or Eq 8, it just a closer
estimate. Newton’s is an iterative method and requires that the estimated error to be:
𝑒𝑖 = |𝑥𝑖+1 − 𝑥𝑖 | < 𝑒𝑟𝑟𝑜𝑟 𝑡𝑜𝑙𝑒𝑟𝑎𝑛𝑐𝑒 Eq.13
The error tolerance is assumed by the customer. If we assume an error tolerance of 1𝑥10−5 (this means
0.00001). For the current iteration:
𝑒0 = |𝑥1 − 𝑥𝑜 | = |1.12766 − 1.0| = 0.12766 Eq.14
Because 𝑒0 = 0.12766 > 1𝑥10−5 , the process needs to be repeated, assuming that the new root
estimated is now 𝑥1 = 1.12766, thus Eq 7 for a new iteration yields (𝑖 = 1):
Still 𝑒1 = 0.000243768 > 1𝑥10−5 then, repeat the process until Eq.13 is satisfied:
𝑒𝑖 < 𝑒𝑟𝑟𝑜𝑟 𝑡𝑜𝑙𝑒𝑟𝑎𝑛𝑐𝑒 (1𝑥10−5 )
Therefore, the last value of 𝑥 = 1.127415806 in the above table is the root and solves Eq.8, and Eq.6.
This is the value of 𝑦1 for the first-time step in the solution of ODE by Backward Euler in Eq.6.
NEXT TASKS: This means you are ready to compute the next time step. In our matlab code, all the burden
of the root finding step is alleviated by the function fsolve. Professor: didn’t you say ‘quick solution by
hand’? where is the ‘quick’part, shouldn’t be re-labeld as the ‘slow solution by hand’?
𝑗 𝑡𝑗 𝑦𝑗
0 0 1
1 0.1 1.127415806
… … …
11 1.0
𝑦2 = 𝑦1 + ℎ (1 + 2𝑡2 )√𝑦2
APPENDIX-1
% Plot
f=@(x) 1+0.12*sqrt(x)-x;
fplot(f,[0,2]);
grid on
title('1+0.12*sqrt(x)-x');
APPENDIX-2
ℎ
In the code below four different values of h are used, each new one is half the previous one: ℎ𝑖+1 = 2𝑖.
The nonlinear algebraic equation is solved with the matlab function fsolve. The estimated error is
computed as 𝑒𝑖 = |𝑦𝑖𝑘 − 𝑦𝑖𝑘+1 |, where 𝑘 and 𝑘 + 1 are two successive iterations and 𝑖 is the node label.
Also, GDE is computed with the maximum error in each iteration.
clc, clear
close all
clf
% table title
fprintf(fid,'%7s %7s %7s %10s\n','i','t(i)','y(i)','er(i)');
for jj=1:1:4 % Four runs with different h’s.
fprintf(fid,'-------------------------------------------------\n');
fprintf(fid,' h =%f \n',h);
for ii=1:1:(length(t)-1)
% Root finding with matlab function fzero
yo=y(ii); tn=t(ii+1);
fun=@(yn) yo+h*(1+2*tn)*sqrt(yn)-yn;
y(ii+1)=fzero(fun,yo);
end
end
hold off
fclose(fid);
OUTPUT ('EulerOut2.m') Selected data points are shown: