Professional Documents
Culture Documents
ANALYSIS LABORATORY
JADAVPUR UNIVERSITY
DEPARTMENT OF CHEMICAL
ENGINEERING
CLASS: UG-II
SECTION: A-1
GROUP NUMBER: 4
GROUP MEMBERS:
DEBASMITA KUMAR
(ROLL:001310301014)
ANJIK
CHOWDHURY(ROLL:001310301015)
ASHWIN
AGARWAL(ROLL:001310301016)
BIPRATEEP
BANERJEE(ROLL:001310301017)
DATE OF SUBMISSION: - 23/02/2015
DAY 5
PROBLEM STATEMENT:
In these problems use different time steps. Plot the
results using any package and compare with
explicit Eulers technique.
The empirical equation for the worlds population, y
dy
as a function of time is given by dt =4.25713 10 y , y =10
12
2.010101
Debasmita Kumar
MATHEMATICAL BACKGROUND
EXPLICIT EULER METHOD
Suppose that we want to approximate the solution of the initial value
problem
y ' ( t )=f (t , y )
yn
t n t n+1=t n +h .
tn
y n y ( tn )
yi
y n+1
is an explicit function
for i n .
to
and
Combining both equations, one finds again the Euler method. This line of
thought can be continued to arrive at various linear multistep methods.
IMPLICIT EULER METHOD
Consider the ordinary differential equation
y ' ( t )=f (t , y )
y0
yk
t0
y 0 , y 1 , y 2 , ..
such
y k+1 .
[i +1]
[i ]
y [0]
k+1 = y k , y k +1 = y k +hf (t k +1 , y k+1 )
from
to
ALGORITHM
Step 1: Start
y1=y0;
x0=y1;
//do-loop to solve the differential equation by Implicit Euler method
for(j=1;j<=steps;j++)
{
//do-loop to find the root by Newton-Raphson method
do
{
fx=F(x0);
fdx=FD(x0);
xn=x0-fx/fdx;
if (fabs((xn-x0)/xn) < EPS)
flag=0;
else
x0=xn;
}while(flag==1);//do-loop ends
x0=y1;
y2=xn;
y1=y2;
}//for loop ends
}
return y2;
if(h>1)
cout<<"\nUse a smaller step size"<<endl;
}while(h>1);//do-loop ends
cout<<"\nEnter base year"<<endl;
cin>>x0;
cout<<"\nEnter number of years for which you want to calculate population"<<endl;
cin>>n;
cout<<"\nEnter population for base year"<<endl;
cin>>y0;
/*population is an array that stores the population computed by Explicit, Implicit Euler methods
and the analytical solution*/
//year is an array to store the years for which population is calculated
int population[3][n];
int year[i];
cout<<"\nEnter the years for which you want to calculate population"<<endl;
SAMPLE OUTPUT
We have the empirical equation for the world's population as a
function of time
This is given as a differential equation:
dy/dt=4.25713*10^-12*y^2.010101
This program solves this differential equation.
We will use the Explicit and Implicit Euler methods.
Finally we will tabulate these along with the analytical solution.
Enter the step size for Explicit Euler calculation.
It should ideally be a number less than 1.
Smaller step size gives more accurate results.
0.01
Enter base year
1840
Explicit Euler
Implicit Euler
Exact Solution
1850 1055403622
1055409962
1055434158
1860 1117342958
1117357587
1117380944
1870 1187049399
1187074933
1187096783
1880 1266084756
1266124748
1266144133
1890 1356460126
1356519490
1356535016
1900 1460810100
1460895750
1460905362
1910 1582654857
1582776742
1582777361
1920 1726806704
1726979511
1726966413
1930 1900023325
1900269394
1900235139
1940 2112102149
2112456737
2112389196
PLOT
YEAR
ANALYTIC
AL
SOLUTION
185
0
1860
10554341
58
11173809
44
11870967
83
12661441
33
13565350
16
14609053
62
15827773
61
17269664
13
19002351
39
21123891
96
1870
1880
1890
1900
1910
1920
1930
1940
1860
1880
1900
1920
EXACT SOLUTION
1940
1960
1860
1880
1900
1920
1940
EXPLICIT EULER
YEA
R
EXPLICIT
EULER
1850
105540362
2
111734295
8
118704939
9
126608475
6
IMPLICIT
135646012
EULER
6
146081010
105540996
0
1582654852
111735758
7
1726806707
118707493
4
1900023323
126612474
5
2112102148
135651949
9
0
146089575
0
158277674
2
172697951
1
190026939
4
211245673
7
1860
1870
1880
YEAR
1890
1900
1850
1910
1860
1920
1870
1930
1880
1940
1890
1900
1910
1920
1930
1940
1960
1860
1880
1900
1920
1940
1960
IMPLICIT EULER
COMMENTS
A few points should be noted about the program.
Firstly, the selection of step size is important for the accuracy of
the solution for both methods. The smaller the step size the
lesser is the error or deviation from the analytical solution. That
is why an if-check has been used to see if the step size input by
the user is sufficiently small or not.
For the Implicit Euler method, we need to use the NewtonRaphson method to solve for y n+1 . For Newton-Raphson method,
we take the initial value as the population for the base year
since we know that the root will be something of the same order.
Also for the computations involved in the Implicit Euler Method,
we have pre-defined two variables F(y) and FD(y) at the
beginning of the program. This avoids unnecessarily defining
new functions or making the existing ones cumbersome. The
condition for termination of Newton Raphson is that the
consecutive values of the iterate have a difference less than the
tolerance value.
For the analytical solution, the function for y was calculated from
before by simple integration. Now with the values of time input
by the user, we can find the value of population by simple
substitution.
In order to avoid the use of too many variables and also to easily
print the population values in a tabular form for the 3 different
methods we use an array to store the values of population and
an array for the years for which the user wishes to calculate the
projected value of population.
The advantage of using the Implicit Euler Method lies in the fact
that for a stiff problem it requires lesser number of computations
as compared to the Explicit Euler Method to reach the solution.
Hence we may say that the Implicit Euler method is slightly more
accurate than the Explicit Euler method.