The analytical method of solution of differential equation is time consuming and tedious. Sometimes it fails to give accurate solution to complicated problems. In order to save time and labor, methods of numerical solution of differential equations such as Euler’s method, Modified Euler’s Method, Runge Kutta Method etc. have been developed.
Here, we are going to discuss a C program for Modified Euler’s method with its source code and sample output. The program is designed for numerical solution of ordinary differential equations or initial value problems in which all the initial conditions are specified.
The input data for Modified Euler’s Method in C given below are initial and final values of x i.e. x0 and xn, initial value of y i.e y0 and the value of increment i.e h.
Here’s how the C source code for Modified Euler’s method works:
- When the program is executed, it checks the error and if the program is found to be error free, the program runs. Firstly, it asks the value of initial condition i.e. initial value of x and y, value of increment h, and final value of x.
- After getting the initial condition, this C program calls the defined function float fun(float,float) for the calculation of slope. The function for calculation of slope is:-
y’ = x2 + y
- Then, value of x is increased by h i.e. x1 = x0 + h and so on. Using the new value of x and y, new slope is calculated. Mean slope of this newly calculated and initial slope is calculated.
- The new value of y is : y= y0 + h * slope. The value of x is not increased till the any two consecutive value of y are found to be same or with the given limit of tolerance.
- The process is repeated till the initial value of x is not equal to the final value of x.
- Finally, the program prints the intermediate as well as final values of x and corresponding y. These values can be transferred to Curve Software to obtain curve and its equations.
Source Code for Modified Euler’s Method in C:
printf("\n C program for Modified Euler Method \n\n");
printf(" Enter the initial value of x:");
printf("\n Enter the value of increment h:");
printf("\n Enter the final value of x:");
printf("\n Enter the initial value of the variable y :");
printf("\n\n The respective values of x and y are\n x \t y\n\n");
float fun(float a,float b)
Smaller the value of h, higher will be the accuracy of the result obtained from this program for modified Euler’s method in C. This method was developed by Leonhard Euler during the 1770s. Modified Euler’s method gives greater improvement in accuracy over the Euler’s method; but it is a bit long and tedious to some extent.