Académique Documents
Professionnel Documents
Culture Documents
8. Approximate y and z by using Picard’s method for the solution of simultaneous differential
equations
dy dz
= 2x + z, = 3xy + x2z
dx dx
with y = 2, z = 0 at x = 0 up to third approximation.
dy
9. Using Picard’s method, obtain the solution of = x(1 + x3y), y (0) = 3
dx
Tabulate the values of y(0.1), y(0.2).
Euler’s method is the simplest one-step method and has a limited application
because of its low accuracy. This method yields solution of an ordinary
differential equation in the form of a set of tabulated values.
In this method, we determine the change Δy is y corresponding to small
increase in the argument x. Consider the differential equation
dy
= f ( x, y) , y(x0) = y0 (7)
dx
Let y = g(x) be the solution of (7). Let x0, x1, x2, ...... be equidistant values
of x.
In this method, we use the property that in a small interval, a curve is
nearly a straight line. Thus at the point (x0, y0), we approximate the curve by
the tangent at the point (x0, y0).
)
Y ,y1
)
(f x 1
g(x
pe Q2
y=
slo
, y 0)
e f(x 0
slop
Q1 y2
P0
y1
y0
X
O x0 x1 x2
This gives the y-coordinate of any point on the tangent. Since the curve is
approximated by the tangent in the interval (x0, x1), the value of y on the curve
corresponding to x = x1 is given by the above value of y in eqn. (8) approximately.
Putting x = x1(= x0 + h) in eqn. (8), we get
y1 = y0 + hf(x0, y0)
Thus Q1 is (x1, y1)
Similarly, approximating the curve in the next interval (x1, x2) by a line
through Q1(x1, y1) with slope f(x1, y1), we get
y2 = y1 + hf(x1, y1)
In general, it can be shown that,
NOTE In Euler’s method, the curve of the actual solution y = g(x) is approximated
by a sequence of short lines. The process is very slow. If h is not properly
chosen, the curve P0Q1Q2 ...... of short lines representing numerical solution
deviates significantly from the curve of actual solution.
1. Function F(x,y)=(x–y)/(x+y)
2. Input x0,y0,h,xn
3. n=((xn–x0)/h)+1
4. For i=1,n
5. y=y0+h*F(x0,y0)
6. x=x+h
494 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES
7. Print x0,y0
8. If x<xn then
x0=x
y0=y
ELSE
9. Next i
10. Stop
START
F(x, y) = (x – y)/(x + y)
n = (xn – x0)/h + 1
For i = 1, n
y = y0 + h*F(x0, y0)
x=x+h
Print x0, y0
If No
x < xn
Yes
x0 = x
y0 = y
STOP
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 495
#include<stdio.h>
#define F(x,y) (x–y)/(x+y)
main ( )
{
int i,n;
float x0,y0,h,xn,x,y;
printf("\n Enter the values: x0,y0,h,xn: \n");
scanf ("%f%f%f%f",&x0,&y0,&h,&xn);
n=(xn–x0)/h+1;
for (i=1;i<=n;i++)
{
y=y0+h*F(x0,y0);
x=x0+h;
printf("\n X=%f Y=%f",x0,y0);
if(x<xn)
{
x0=x;
y0=y;
}
}
return;
}
6.11.1 Output
Enter the values: x0,y0,h,xn:
0 1 0.02 0.1
X=0.000000 Y=1.000000
X=0.020000 Y=0.980000
X=0.040000 Y=0.960800
X=0.060000 Y=0.942399
X=0.080000 Y=0.924793
X=0.100000 Y=0.907978
496 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES
The modified Euler’s method gives greater improvement in accuracy over the
original Euler’s method. Here the core idea is that we use a line through (x0, y0)
whose slope is the average of the slopes at (x0, y0) and (x1, y1(1)) where y1(1) = y0 +
hf(x0, y0). This line approximates the curve in the interval (x0, x1).
Geometrically, if L1 is the tangent at (x0, y0), L2 is a line through (x1, y1(1)) of
slope f(x1, y1(1)) and L is the line through (x1, y1(1)) but with a slope equal to the
average of f(x0, y0) and f(x1, y1(1)) then the line L through (x0, y0) and
parallel to L is used to approximate the curve in the interval (x0, x1). Thus the
ordinate of the point B will give the value of y1. Now, the eqn. of the line AL is
given by
Y L
(x1, y1)
B
L2
L
(x0, y0)
L1
A (1)
(x1, y1 )
X
O x0 x1
y1 = y0 + (x1 – x0)
LM f ( x , y ) + f ( x , y ) OP
0 0 1 1
(1)
MN 2 PQ
= y0
L f (x , y ) + f (x , y ) OP
+h M 0 0 1 1
(1)
MN 2 PQ
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 497
h
y1(n+1) = y0 + [f(x0, y0) + f{x1, y1(n)}] ; n = 0, 1, 2, ......
2
where y1(n) is the nth approximation to y1.
The above iteration formula can be started by choosing y1(1) from Euler’s
formula
y1(1) = y0 + hf(x0, y0)
Since this formula attempts to correct the values of yn+1 using the predicted
value of yn+1 (by Euler’s method), it is classified as a one-step predictor-corrector
method.
1. Function F(x)=(x–y)/(x+y)
2. Input x(1),y(1),h,xn
3. yp=y(1)+h*F(x(1),y(1))
4. itr=(xn–x(1))/h
5. Print x(1),y(1)
6. For i=1,itr
7. x(i+1)=x(i)+h
8. For n=1,50
9. yc(n+1)=y(i)+(h/2*(F(x(i),y(i))+F(x(i+1),yp))
10. Print n,yc(n+1)
11. p=yc (n+1)-yp
12. If abs(p)<.0001 then
goto Step 14
ELSE
yp=yc(n+1)
13. Next n
14. y(i+1)=yc(n+1)
15. print x(i+1),yp
16. Next i
17. Stop
498 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES
START
F(x) = (x – y)/(x + y)
For i = 1, itr
x(i + 1) = x(i) + h
For n = 1, 50
Print n, yc(n + 1)
p = yc(n + 1) – yp
If Yes
abs(p) < 0.0001
No
yp = yc(n + 1)
y(i + 1) = yc(n + 1)
STOP
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 499
#include<stdio.h>
#include<math.h>
#define F(x,y) (x-y)/(x+y)
main ()
{
int i,n,itr ;
float x[5],y[50],yc[50],h,yp,p,xn;
printf("\n Enter the values: x[1],y[1],h,xn:\n");
scanf("%f%f%f%f",&x[1],&y[1],&h,&xn);
yp=y[1]+h*F(x[1],y[1]);
itr=(xn-x[1])/h;
printf("\n\n X=%f Y=%f\n",x[1],y[1];
for (i=1;i<=itr;i++)
{
x[i+1]=x[i]+h;
for (n=1;n<=50;n++)
{
yc[n+1]=y[i]+(h/2.0)*(F(x[i],y[i])+F(x[i+1],yp));
printf("\nN=%d Y=%f",n,yc[n+1]);
p=yc[n+1]-yp;
if(fabs (p)<0.0001)
goto next;
else
yp=yc[n+1];
}
next:
y[i+1]=yc[n+1];
printf("\n\n X=%f Y=%f\n",x[i+1], yp);
}
return;
}
500 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES
6.15.1 Output
Enter the values: x[1],y[1],h,xn:
0 1 0.02 0.06
X=0.000000 Y=1.000000
N=1 Y=0.980400
N=2 Y=0.980400
X=0.020000 Y=0.980400
N=1 Y=0.961584
N=2 Y=0.961598
X=0.040000 Y=0.961584
N=1 Y=0.943572
N=2 Y=0.943593
X=0.060000 Y=0.943572
EXAMPLES
dy y – x
Example 1. Given = with y = 1 for x = 0. Find y approximately for
dx y + x
x = 0.1 by Euler’s method.
Sol. We have
dy y– x
= f(x, y) = ; x0 = 0, y0 = 1, h = 0.1
dx y+ x
Hence the approximate value of y at x = 0.1 is given by
y1 = y0 + hf(x0, y0) | using yn+1 = yn + hf(xn, yn)
FG 1 – 0 IJ = 1.1
= 1 + (.1) +
H 1 + 0K
Much better accuracy is obtained by breaking up the interval 0 to 0.1 into
five steps. The approximate value of y at xA = .02 is given by,
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 501
y1 = y0 + hf(x0, y0)
FG 1 – 0 IJ = 1.02
= 1 + (.02)
H 1 + 0K
At xB = 0.04, y2 = y1 + hf(x1, y1)
FG 102
. – .02 I
H 1.02 + .02 JK = 1.0392
= 1.02 + (.02)
y = 1.0392 + (.02) G
F 1.0392 – .04 IJ = 1.0577
At xC = .06, 3
H 1.0392 + .04 K
At xD = .08, y = 1.0577 + (.02) G
F 1.0577 – .06IJ = 1.0756
4
H 1.0577 + .06 K
y = 1.0756 + (.02) G
F 1.0756 – .08IJ = 1.0928
At xE = .1, 5
H 1.0756 + .08 K
Hence y = 1.0928 when x = 0.1
E
Y
C
B
A
X
O A¢ B¢ C¢ D¢ E¢
dy
Example 2. Solve the equation = 1 – y with the initial condition x = 0, y = 0
dx
using Euler’s algorithm and tabulate the solutions at x = 0.1, 0.2, 0.3.
Sol. Here, f(x, y) = 1 – y
Taking h = 0.1, x0 = 0, y0 = 0, we obtain
y1 = y0 + hf(x0, y0)
= 0 + (.1) (1 – 0) = .1
∴ y(0.1) = 0.1
502 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES
x y(x)
0 0
0.1 0.1
0.2 0.19
0.3 0.271
∴ f(x0, y0) = x0 + | y 0 | = 0 + 1 = 1
We have y1(1) = y0 + hf(x0, y0)
= 1 + (.2) . 1 = 1.2
y1(2) = y0 + h
LM f (x , y ) + f { x , y } OP
0 0 1 1
( 1)
MN 2 PQ
= 1 + (0.2) FG
1 + 1.2954 I
H 2 JK = 1.2295
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 503
(2 )
Again, f{x1, y1(2)} = x1 + | y1 | = 0.2 + 12295
. = 1.3088
h
So, y1(3) = y0 + [f(x0, y0) + f{x1, y1(2)}]
2
0.2
=1+ [1 + 1.3088] = 1.2309
2
We have f{x1, y1(3)} = 0.2 + 1.2309 = 1.309
.2
Then y1(4) = 1 + [1 + 1.309] = 1.2309
2
Since, y1(4) = y1(3) hence y1 = 1.2309
Now, y2(1) = y1 + hf(x1, y1)
= 1.2309 + (0.2) [0.2 + 1.2309 ]
= 1.4927 |∵ x1 = 0.2
dy
Example 4. Given that = log10 (x + y) with the initial condition that y = 1
dx
when x = 0. Find y for x = 0.2 and x = 0.5 using Euler’s modified formula.
Sol. Let x = 0, x1 = 0.2, x2 = .5 then y0 = 1
y1 and y2 are yet to be computed.
Here, f(x, y) = log (x + y)
∴ f(x0, y0) = log 1 = 0
∴ y1(1) = y0 + hf(x0, y0) = 1
f{x1, y1(1)} = log {x1 + y1(1)} = log (.2 + 1) = log (1.2)
h
∴ y1(2) = y0 + [f(x0, y0) + f{x1, y1(1)}]
2
.2
=1+ [0 + log (1.2)] = 1.0079
2
.2
Also, y1(3) = 1 + [0 + log (.2 + 1.0079)] = 1.0082
2
.2
y1(4) = 1 + [0 + log (.2 + 1.0082)] = 1.0082
2
Since, y1(4) = y1(3) hence y1 = 1.0082
To obtain y2, the value of y at x = 0.5, we take,
y2(1) = y1 + hf(x1, y1)
= 1.0082 + 0.3 log (.2 + 1.0082)
= 1.0328 (∵ h = .5 – .2 = .3 here)
h
Now, y2(2) = y1 + [f(x1, y1) + f{x2, y2(1)}]
2
.3
= 1.0082 + [log (.2 + 1.0082) + log (.5 + 1.0328)]
2
= 1.0082 + 0.0401 = 1.0483
.3
Also, y2(3) = 1.0082 + [log (.2 + 1.0082) + log (.5 + 1.0483)]
2
= 1.0082 + .0408 = 1.0490
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS 505
h
∴ y1(4) = y0 + [f(x0, y0) + f{x1, y1(3)}]
2
.2
= .02 + [.1996 + .3938] = .0793 ~
− .079
2
Since y1(3) = y1(4) hence y1 = .079.
ASSIGNMENT 6.2
1. Find y for x = 0.2 and x = 0.5 using modified Euler’s method, given that
dy
= log e ( x + y) ; y(0) = 1
dx
2. Taking h = .05, determine the value of y at x = 0.1 by Euler’s modified method, given
that,
dy
= x2 + y; y(0) = 1
dx
506 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES
dy
3. Given = x2 + y, y(0) = 1, find y(.02), y(.04) and y(.06) using Euler’s modified method.
dx
dy
4. Apply Euler’s method to the initial value problem = x + y, y(0) = 0 at x = 0 to x = 1.0
dx
taking h = 0.2.
dy
5. Use Euler’s method with h = 0.1 to solve the differential equation = x2 + y2, y(0) = 1
dx
in the range x = 0 to x = 0.3.
dy FG y IJ
6. Solve for y at x = 1.05 by Euler’s method, the differential equation
dx
=2–
H xK where