Differential Equations
Differential Equations
7: VIM
Preface
This tutorial was made solely for the purpose of education and it was designed for students taking Applied Math
0330. It is primarily for students who have very little experience or have never used Mathematica and programming
before and would like to learn more of the basics for this computer algebra system
(https://en.wikipedia.org/wiki/Computer_algebra_system). As a friendly reminder, don't forget to clear variables in use
and/or the kernel. The Mathematica commands in this tutorial are all written in bold black font, while Mathematica
output is in normal font.
Finally, you can copy and paste all commands into your Mathematica notebook, change the parameters, and run
them because the tutorial is under the terms of the GNU General Public License (GPL
(https://en.wikipedia.org/wiki/GNU_General_Public_License)). You, as the user, are free to use the scripts for your
needs to learn the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long
as this tutorial is accredited appropriately. The tutorial accompanies the textbook Applied Differential Equations. The
Primary Course (https://www.crcpress.com/Applied-Differential-Equations-The-Primary-
Course/Dobrushkin/9781439851043) by Vladimir Dobrushkin, CRC Press, 2015;
http://www.crcpress.com/product/isbn/9781439851043 (http://www.crcpress.com/product/isbn/9781439851043)
To illustrate the basic concept of the He’s VIM, consider the following general nonlinear equation:
http://www.cfm.brown.edu/people/dobrush/am33/Mathematica/ch7/vim.html 1/9
11/10/2018 MATHEMATICA TUTORIAL, Part 1.7: VIM
where L is the linear differential operator of order m, N is the nonlinear operator, and g is the input (known) function.
He has modified the general Lagrange multiplier method to an iteration method called as correction functional. The
basic character of the method is to construct a correction functional for the aforementioned equation, which reads as
~
u n+1 (t) = u n (t) + ∫ λ(s) {L [u n (s)] − N [u n (s)] − g(s)} ds,
0
variation., i.e., δu = 0. Having λ obtained, an iteration formula should be used for the determinantion of the
~
n
successive approximations un+1(t) of the solution u(t). The initial approximation u0(t) can be arbitrary function;
however, it is usually selected based on the auxiliary conditions (such as the initial or boundary conditions).
Consequently, the solution is given by
The main problem with VIM is the determination of the Lagrange multiplier, and there are known many forms of
them. It could be achieved by making the correction functional stationary. Taking variation with respect to the variable
un, noticing δun(0)=0, we get
~
δu n+1 (t) = δu n (t) + δ ∫ λ {L [u n (s)] − N [u n (s)] − g(s)} ds
0
t
(m−1) (m−2)
∣ ′ ∣ m−1 (m−1) ∗
= δu n (t) + λ δu n − λ δu n + ⋯ + (−1) λ δu n ∣
∣ + ∫ L [λ] δu n ds = 0,
∣ ∣ s=t
s=t s=t
0
subject to some auxiliary conditions on the diagonal s = t. Here L* is adjoint differential operator for L. In other words,
if L is a m-th order linear differential operator, we need to find an extremum form the following functional
t t
(m)
′
∫ λ L [u n (s)] ds = ∫ λ f (s, u n (s), u n (s), … , u n ) ds.
0 0
′ (m)
I = ∫ F (s, y(s), y (s), … , y ) ds
0
that attains an extremum on solutions of the generalized Euler--Lagrange equation (or simply the Euler equation
(https://en.wikipedia.org/wiki/Euler%E2%80%93Lagrange_equation)):
2 m
∂F d ∂F d ∂F d ∂F
m
− ( ) + ( ) − ⋯ + (−1) ( ) = 0.
′ 2 ′′ m (m)
∂y ds ∂y ds ∂y ds ∂y
Using the above equation, we see that extremum of the variational functional is given as follows
2 m
∂ (λ f ) d ∂ (λ f ) d ∂ (λ f ) d ∂ (λ f )
m
− ( ) + ( ) − ⋯ + (−1) ( ) = 0.
′ 2 ′′ m (m)
∂y ds ∂y ds ∂y ds ∂y
Solving these equations is sufficient to determine the Lagrange multipliers. We show how it works in a series on
examples.
http://www.cfm.brown.edu/people/dobrush/am33/Mathematica/ch7/vim.html 2/9
11/10/2018 MATHEMATICA TUTORIAL, Part 1.7: VIM
′ 2
y = 3y − y + 2 x, y(0) = 0.
′ ~2
yn+1 (x) = yn (x) + ∫ λ(x, s) {yn (s) − 3 yn (s) + y − 2 s} ds, n = 0, 1, 2, … .
n
0
′ ~2
δyn+1 (x) = δyn (x) + δ ∫ λ {yn (s) − 3 yn (s) + y n − 2 s} ds
0
x
′
= δyn (x) + δ ∫ λ {yn (s) − 3 yn (s)} ds
0
t
s=t ′
= δyn (x) + λ δyn (s)| − ∫ [λ + 3 λ] δyn (s) ds.
s=0
0
′
λ (s) + 3 λ(s) = 0,
1 + λ(s)| = 0.
s=t
3(x−s)
λ(x, s) = −e .
x
3(x−s) ′ 2
yn+1 = yn − ∫ e {yn (s) − 3 yn (s) + yn − 2 s} ds, n = 0, 1, 2, … .
0
seriesDSolve[ y'[x] == 2*x + 3*y[x] - (y[x])^2, y, {x, 0, 10}, {y[0] -> 0}]
5
3 x 5 25 187 2551 1217
2 3 4 6 7 8 9 10
y = x + x + x + − x − x − x − x + x + ⋯.
4 4 24 56 448 12096 40320
x
1 10
2 3(x−s) 2 4 2 4 2 3x
y1 (x) = x − ∫ e {2s − 3 s + s − 2 s} ds = x + (27 x − 45 x − 30 x − 10) + e ,
0 81 81
x 3 4
3(x−s) 2
x x 3 5
3 6
253 7
′ 2
y2 = y1 − ∫ e {y − 3 y1 + y − 2 s} ds ≈ x − − − x − x + x + ⋯.
1 1
0 3 4 20 40 840
So we see that calculations become messy very shortly. We ask Mathematica for help.
5
3 x 31 205 4505
2 3 4 7 8 9
y3 (x) ≈ x + x + x + + x + x + x + ⋯,
4 4 56 448 12096
http://www.cfm.brown.edu/people/dobrush/am33/Mathematica/ch7/vim.html 3/9
11/10/2018 MATHEMATICA TUTORIAL, Part 1.7: VIM
which gives correct answer up to the power 6. Then we plot the third approximation y3 and the true solution.
sol = (y[x] /.
DSolve[{y'[x] == 2*x + 3*y[x] - (y[x])^2, y[0] == 0}, y[x], x])[[1]];
Plot[{Callout[sol, "exact"], Callout[y3[x], "three-term VIM approximation"]}, {x,0,1.2}, PlotStyle->Thick]
t t
2 2
yn+1 (t) = yn (t) + 3 ∫ (yn (s) − yn−1 (s)) ds − ∫ (yn (s) − y (s)) ds, n = 1, 2, … ;
n−1
0 0
where y −1
= 0, y0 = 0 (from the initial condition) and
2 2 2
y1 (t) = y0 + ∫ [3 (y0 − y−1 ) − (y − y ) + 2s] ds = t .
0 −1
0
t 5
2 2 3
t
2 2
y2 (t) = t + ∫ [3 (y1 − y0 ) − (y − y )] ds = t + t − ,
1 0
0
5
t 5 8 10
3 t 13 t 2 t
2 3 2 2 2 3 4 6 9
y3 (t) = t + t + ∫ [3 (y2 − y1 ) − (y − y )] ds = t + t + t − − t + + t − ,
2 1
0
4 5 30 20 45 275
t 5 8
2 3 2 3
3 4
t 13 6
19 7
107 t 41 9
111 10
2 2
y4 (t) = t + t + ∫ [3 (y3 − y2 ) − (y − y )] ds = t + t + t + − t − t − + t + t + ⋯.
3 2
0 4 4 30 35 560 432 700
2
d T
+ T (x) + 2x = 0, (0 < x < ℓ, T (0) = 4, T (ℓ) = 3.
2
dx
Here T is the temperature within the rod of length ℓ, and we set for simplicity ℓ=2. Its correction functional can we
written as
′′
Tn+1 (x) = Tn (x) + ∫ λ {Tn (s) + Tn (s) + 2s} ds, n = 0, 1, 2, … .
0
Taking variation with respect to the dependent avriable Tn, and noticing that &deltaTn(0)=0, we have
http://www.cfm.brown.edu/people/dobrush/am33/Mathematica/ch7/vim.html 4/9
11/10/2018 MATHEMATICA TUTORIAL, Part 1.7: VIM
′′
δTn+1 (x) = δTn (x) + δ ∫ λ {Tn (s) + Tn (s) + 2s} ds
0
x
′ ′ ′′
= δTn (x) + λ δTn (s)| − λ δTn (s)| + ∫ [λ + λ] δTn (s)ds
s=x s=x
0
for all variations δTn and δT'n. This yields the following equations:
′′
λ + λ = 0,
λ(s)| = 0,
s=x
′
1 − λ (s)| = 0.
s=x
′′
Tn+1 (x) = Tn (x) + ∫ sin(s − x) {Tn (s) + Tn (s) + 2s} ds, n = 0, 1, 2, … .
0
We choose the initial approximation as a function that satisfies the boundary conditions:
ℓ − x x 3 x
T0 (x) = T (0) + T (ℓ) = 2 (2 − x) + x = 4 − .
ℓ ℓ 2 2
x
3
′′
T1 (x) = T0 (x) + ∫ sin(s − x) {T (s) + T0 (s) + 2s} ds = −2x + 4 cos x + sin x,
0
0
2
x
′′
T2 (x) = T1 (x) + ∫ sin(s − x) {T (s) + T1 (s) + 2s} ds = T1 (x).
1
0
So the iteration stops after first step. We compare it with the exact solution.
T0[x_] = 4 - x/2;
T1[x_] = T0[x] + Integrate[Sin[s - x]*(D[T0[s], s, s] + T0[s] + 2*s), {s, 0, x}]
Plot[{Callout[exact[x], "exact"], Callout[T1[x], "VIM approximation"]}, {x,0,2}, PlotStyle->Thick]
′′
T1 (x) = A cos x + B sin x + ∫ sin(s − x) {T (s) + T0 (s) + 2s} ds = A cos x + (B + 2) sin x − 2x.
0
0
http://www.cfm.brown.edu/people/dobrush/am33/Mathematica/ch7/vim.html 5/9
11/10/2018 MATHEMATICA TUTORIAL, Part 1.7: VIM
Next iteration provides a function that is far away from the true solution. ■
2
ÿ + ω y = f (t) with f (t) = A sin ωt + B cos t,
′′ 2
yn+1 (t) = yn (t) + ∫ λ {yn (s) + ω yn (s) − f (s)} ds, n = 0, 1, 2, … .
0
Making the above correction functional stationary, and noticing that δy(0) = 0, we get
′′ 2
δyn+1 (t) = δyn (t) + δ ∫ λ {yn (s) + ω yn (s) − f (s)} ds
0
′ ′ ′′ 2
= δyn (t) + λ(s) δyn (s)| − λ (s) δyn (s)| + ∫ [λ + ω λ] δyn (s) ds.
s=t s=t
0
′′ 2
λ + ω λ = 0,
λ(s)| = 0,
s=t
′
1 − λ (s)| = 0.
s=t
1
λ(t, s) = sin ω(s − t).
ω
t
1
′′ 2
yn+1 (t) = yn (t) + ∫ sin ω(s − t) {yn (s) + ω yn (s) − f (s)} ds, n = 0, 1, 2, … .
ω 0
Now we consider the homogeneous equation corresponding to the given driven equation ÿ + ω y = 0 subject to the 2
given initial conditions; its solution, called the complementary function, can be chosen as the initial approximation
sin ωt
y0 (t) = C1 cos ωt + C2 sin ωt = cos ωt − ,
ω
where C1 and C2 are such constants to satisfy the given initial conditions, y(0) = 1 and y'(0) = -1. Then the iteration
formula gives
t
1
y1 (t) = y0 (t) − ∫ sin ω(s − t) [A sin ωs + B sin ωs] ds
ω 0
A sin ωt Bω
= C1 cos ωt + C2 sin ωt − [t cos ωt − ] + [cos ωt − cos t] ,
2
2 ω ω − 1
http://www.cfm.brown.edu/people/dobrush/am33/Mathematica/ch7/vim.html 6/9
11/10/2018 MATHEMATICA TUTORIAL, Part 1.7: VIM
which is the general solution of the given differential equation (harmonic oscillator).
However, is we apply restricted variations to the correction function, then its exact solution can be arrived at only by
successive iterations. Considering the corresponding homogeneous differential equation ÿ + ω y = 0, we rewrite the 2
′′ 2 ~
yn+1 (t) = yn (t) + ∫ λ {yn (s) + ω y (s)} ds, n = 0, 1, 2, … .
n
0
Here y~ (s) is considered a restricted variation, then the stationary conditions (δy~
n n
= 0 ) of the above correction
functional can be expressed as follows
′′
λ (s) = 0,
λ(s)| = 0,
s=t
′
1 − λ (s)| = 0.
s=t
Therefore, the Lagrange multiplier becomes λ = s − t. This leads to the following iteration formula
′′ 2
yn+1 (t) = yn (t) + ∫ (s − t) {yn (s) + ω yn (s) − f (s)} ds, n = 0, 1, 2, … .
0
t 2 3
2 2
t t
y1 (t) = y0 (t) + ω ∫ (s − t) y0 (s) ds = 1 − t + ω (− + ),
0 2 6
t 2 3 4 5
2 2
t t 4
t t
′′
y2 (t) = y1 (t) + ∫ (s − t) (y (s) + ω y1 (s)) ds = 1 − t + ω (− + ) + ω ( − ),
1
0 2 6 24 120
t 2 3 4 5 6 7
2 2
t t 4
t t 6
t t
′′
y3 (t) = y2 (t) + ∫ (s − t) (y (s) + ω y2 (s)) ds = 1 − t + ω (− + ) + ω ( − ) + ω (− + ),
2
0
2! 3! 4! 5! 6! 7!
n n n 2k+1 2k+1
(−1) 1 ω t
2k 2k k
yn (t) = ∑ ω t − ∑(−1) .
(2k)! ω (2k + 1)!
k=0 k=0
Thus, we obtaine
1
lim yn (t) = cos ωt − sin ωt,
n→∞ ω
¨ 2 ˙
θ + ω sin θ = 0, θ(0) = θ0 , θ (0) = 0.
′′′ ′
u + 4u = f (t), u(0) =
http://www.cfm.brown.edu/people/dobrush/am33/Mathematica/ch7/vim.html 7/9
11/10/2018 MATHEMATICA TUTORIAL, Part 1.7: VIM
References
1. Abbasbandy S (2007), A new application of He’s variational iteration method for quadratic Riccati differential
equation by using Adomian’s polynomials (https://core.ac.uk/download/pdf/82382594.pdf), Journal of Applied
Mathematics and Computing, 207:59–63
2. Tamer A. Abassy, New Applications of the Modified Variational Iteration Method
(https://idosi.org/sns/3(2)12/1.pdf), Studies in Nonlinear Sciences, 2012, Vol. 3, No. 2, pp. 49--61, doi:
10.5829/idosi.sns.2012.3.2.246
3. Tamer A. Abassy, Magdy A. El-Tawil, and H. El-Zoheiry, Exact solutions of some nonlinear partial differential
equations using the variational iteration method linked with Laplace transforms and the Padé technique
(https://core.ac.uk/download/pdf/82475220.pdf), Computers and Mathematics with Applications, 2007, Vol.
54, pp. 940--954.
4. M.A. Fariborzi Araghi, S. Gholizadeh Dogaheh, and Z. Sayadi, The modified variational iteration method for
solving linear and nonlinear ordinary differential equations (http://ajbasweb.com/old/ajbas/2011/October-
2011/406-416.pdf), Australian Journal of Basic and Applied Science, 2011, Vol. 5, No. 10, pp. 406--416.
5. Inan Ates and Ahmet Yildirim, "Comparison between variational iteration method and homotopy perturbation
method for linear and nonlinear partial differential equations with the nonhomogeneous initial conditions,"
Numerical Methods for Partial Differential Equations, 2010, Vol 26, Issue 6, pp. 1581--1593, doi:
https://doi.org/10.1002/num.20511
6. Ji-Huan He, "Variational iteration method---a kind of non-linear analytical technique: some examples,"
International Journal of Non-Linear Mechanics, 1999, Vol 34, 699--708.
7. Ji-Huan He, "Variational iteration method for autonomous ordinary differential systems," Applied Mathematics
and Computation, 2000, Vol. 114, 115--123.
8. Ameina S. Nuseir and Mohammad Al-Towaiq, The modified variational iteration method for solving the
Impenetrable Agar model problem (https://ijpam.eu/contents/2014-96-4/3/3.pdf), International Journal of Pure
and Applied Mathematics, 2014, Vol. 96, No 4, pp. 445--456, doi: http://dx.doi.org/10.12732/ijpam.v96i4.3
9. S. S. Samaee, O. Yazdanpanah, and D. D. Ganji, "New approaches to identification of the Lagrange
multiplier in the variational iteration method," Journal of the Brazilian Society of Mechanical Sciences and
Engineering, 2914, doi: 0.1007/s40430-014-0214-3
10. Tatari M, Dehghan M (2007), "He’s variational iteration method for computing a control parameter in a semi-
linear inverse parabolic equation," Chaos Solitons Fractals, 33(2):671--677.
11. A.-M. Wazwaz (2006), "A study on linear and nonlinear Schrodinger equations by the variational iteration
method," Chaos Solitons Fractals, doi: 10.1016/j.chaos.10.009
12. A.-M. Wazwaz (2007), "The variational iteration method for solving tow forms of Blasius equation on a half-
infinite domain," Applied Mathemathics and Computation, 2007, Vol. 188, Issue 1, pp. 485--491.
13. A.-M. Wazwaz (2007), The variational iteration method for the exact solution of Laplace equation, Physics
Letters A, Vol. 363, No 4, pp. 260--262, doi: 10.1016/j.physleta.2006.11.014
14. A.-M. Wazwaz (2001) The numerical solution of fifth-order boundary value problems by the decomposition
method. Journal of Applied Mathematics and Computing, 136:259–270
15. Wazwaz AM (2007) The variational iteration method for solving a system of PDES. Comput Math Appl
54:895–902
16. Ganji DD, Tari H, Babazadeh H (2007) The application of He’s variational iteration method to nonlinear
equations arising in heat transfer. Physics Letters A, Vol. 363, No. , pp. 213--217
17. Rafei M, Daniali H, Ganji DD (2007) Variational iteration method for solving the epidemic model and the prey
and predator problem. Appl Math Comput 186:1701–1709
18. Tari H, Ganji DD, Rostamian M (2007) Approximate solution of K (2, 2), KdV and modified KdV equations by
variational itera- tion method, homotopy perturbation method and homotopy ana- lysis method. Int J
Nonlinear Sci Numer Simul 8:203–210
19. Ganji DD, Sadighi A (2006) Application of He’s methods to nonlinear coupled systems of reactions. Int J
Nonlinear Sci Numer Simul 7(4):411–418
http://www.cfm.brown.edu/people/dobrush/am33/Mathematica/ch7/vim.html 8/9
11/10/2018 MATHEMATICA TUTORIAL, Part 1.7: VIM
20. Ganji DD, Jannatabadi M, Mohseni E (2006) Application of He’s variational iteration method to nonlinear
Jaulent–Miodek equa- tions and comparing it with ADM. Journal of Applied Mathematics and Computing,
207:35–45
21. Ganji DD, Tari H, Jooybari MB (2007) Variational iteration method and homotopy perturbation method for
evolution equations. Comput Math Appl 54:1018–1027
22.
http://www.cfm.brown.edu/people/dobrush/am33/Mathematica/ch7/vim.html 9/9