SlideShare a Scribd company logo
1
Numerical solutions of ordinary first order
differential equations by the Euler method
Name : Sri Bhuvaneshwari A
Register No : 34423009
2
Euler’s Method
x0 x1 x x0 x1 x
f(x)
Given a differential equation y’= f (x, y)
and an initial condition (x0,y0)
We can approximate how the values of the function change using method
f(x)
error
error
h h
3
Euler’s Method
• The derivative of a function y(x) represents the slope of the tangent line at any point (x, y):
• For small h, we approximate this as:
• This equation expresses the idea that the rate of change of y is given by the function f(x, y).
• Rearranging the equation:
• which gives us Euler’s method formula:
where:
yn​is the current value,
xn​is the current step,
h is the step size,
f(xn,yn) is the slope at that point.
=
y(x+h) = y(x) + h f(x,y)
yn+1​
= yn​
+ h f(xn​
, yn​
)
4
Example
• Given Differential Equation:
with initial condition y(0)=1, and we want to find y(0.2) using step size h=0.1.
• Solution:
So, the Euler’s method approximation for y(0.2) is 1.22.
S.No x y
1 0 1
2 0.1 1.1
3 0.2 1.22
Step-by-Step Calculation:
Step 1: At x0 = 0, y0 = 1,
f(0,1)= 0 + 1 = 1
y1​
=y0​+ h f(x0​
,y0​
) =1+0.1×1 = 1.1
Step 2: At x1 = 0.1, y1 = 1.1
f(0.1, 1.1) = 0.1+1.1 = 1.2
y2​= y1​+ h f(x1​
,y1​
) = 1.1+0.1×1.2 = 1.22
yn+1​
= yn​
+ h f(xn​
, yn​
)
f(x,y) =
x+y.
5
Improved Euler’s Method (Heun’s Method/ Euler-Cauchy Method)
x0 x1 x
x0 x1 x x0 x1 x
x0 x1 x
f(x) f(x)
f(x)
y1 y1
y0 y0
 y’= f (x, y)
 Initial condition:(x0,y0)
 x1= x0+h , y1= y0 + h f(x0,y0)
 m = f(x0+h , y0 + h f(x0,y0)
 Average of the slopes:
y1=
yn+1 ​
= yn​+ ​[f(xn​, yn​
) + f(xn+1​,ypredict ​
)]
6
Example
• Given Differential Equation:
with initial condition y(0)=1, and we want to find y(0.2) using step size h=0.1.
• Solution:
• So, the Improved Euler’s method approximation for y(0.2) is 1.2421.
• Comparison of Results:
S.No x y
1 0 1
2 0.1 1.11
3 0.2 1.2421
Step-by-Step Calculation:
Step 1: At x0 =0, y0 = 1
Predict y1
∗
​
:
y1
∗
​= y​
0 + hf(0,1) =1 + 0.1×1 = 1.1
Compute f(x1,y1
∗
):
f(0.1, 1.1) = 0.1 + 1.1 = 1.2
Corrected y1​
:
y1​
= 1 + (0.1​
(1+1.2) /2)
= 1 + 0.1×1.1
= 1.11
Step 2: At x1 = 0.1, y1 = 1.11
f(0.1, 1.11) = 1.21
Predict y2
∗
​
:
y2​
∗
= 1.11 + 0.1×1.21 = 1.231
Compute f(x2, y2
∗
):
f(0.2, 1.231) = 0.2 + 1.231 =1.431
Corrected y2:
y2​= 1.11 + (0.1​
(1.21+1.431) /2)
= 1.11 + 0.1×1.3205
= 1.2421
Method y(0.2) Approximation
Euler's Method 1.22
Improved Euler's Method 1.2421
 y1= y0 + h f(x0,y0)
 y1=
7
Algorithm for Euler’s Method and Improved Euler Method:
• Step 1: Define the Problem
=
Given:
1. Initial values: x0 , y0
2. Step size: h
3. Final value of x (denoted as xn​
)
• Step 2: Euler’s Method Algorithm
Euler’s method is a simple numerical approach that approximates the solution by taking small steps.
1. Start with initial values (x0 , y0).
2. Repeat until x reaches xn​
3. Compute the next y value using the formula: ynew = y + h f (x , y )
⋅
4. Update x as: xnew = x + h
5. Print x, y.
6. Stop when x exceeds or reaches xn​
.
8
• Step 3: Improved Euler’s Method Algorithm (Heun’s Method)
The Improved Euler's Method corrects the error in the basic Euler's Method by using an average slope.
1. Start with initial values (x0 ,y0).
2. Repeat until x reaches x n​ :
 Compute the first slope (predictor step):
k1 ​
= f (x, y)
 Compute the predicted y value:
y predict​= y + h k
⋅ 1​
 Compute the second slope using the predicted value:
k2​= f (x + h, y predict​
)
 Compute the corrected y value:
y new ​
= y + ​ (k
⋅ 1​
+k2​
)
 Update x as:
x new ​
= x + h
 Print x, y.
3. Stop when x exceeds or reaches x n ​
.
9
• Step 4: Implement User Input
Ask the user to enter
1. Initial values x0,y0
2. Step size h
3. Final value x n
4. Pass these values to both Euler’s and Improved Euler’s method functions.
• Summary of the Algorithm
1. Take user input for x0, y0, h, xn​
.
2. Compute the numerical solution using Euler’s Method
Use the formula ynew = y + h f(x, y).
⋅
3. Compute the numerical solution using Improved Euler’s Method
Use predictor-corrector steps.
4. Print results for both methods.
Taylor Series for y(x): y(xn+1​
) = y(xn​
) + h y (x
′ n​
) + ​​
y (x
′′ n​
) + ​ y (x
′′′ n​
)+…
y(xn+1​
) ​
= y(xn​
) ​
+ h f(xn​
,yn​
) + ​ (​
+ ​​
f(xn​
,yn​
)) + y (x
′′′ n​
)
Heun’s Method: y(xn+1​
) ​
= y(xn​
) + ​[f(xn​, yn​
) + f(xn+1​,ypredict ​
)]
10
C Program
1. #include <stdio.h>
2. float f(float x, float y) // Function defining the differential equation dy/dx = f(x, y)
3. { return x + y; // Example equation: dy/dx = x + y
4. }
5. void euler_method (float x, float y, float h, float xn) // Euler's Method
6. {
printf ("nEuler's Method:n");
7. printf ("xttyn");
8. while (x <= xn)
9. {
10. printf ("%ft%fn", x, y);
11. y = y + h * f(x, y); // Euler formula
12. x = x + h;
13. }
14. }
11
15. void improved_euler (float x, float y, float h, float xn) // Improved Euler's Method (Heun's Method)
16. {
17. float y_predict;
18. printf ("nImproved Euler's Method:n");
19. printf ("xttyn");
20. while (x <= xn )
21. {
22. printf ("%ft%fn", x, y);
23. float k1 = f(x, y);
24. y_predict = y + h * k1; // Predictor
25. float k2 = f(x + h, y_predict);
26. y = y + (h / 2) * (k1 + k2); // Corrector
27. x = x + h;
28. }
29. }
12
30. int main()
31. {
32. float x, y, h, xn;
33. printf ("Enter initial value of x (x0): "); // Taking user input
34. scanf ("%f", &x);
35. printf ("Enter initial value of y (y0): ");
36. scanf ("%f", &y);
37. printf ("Enter step size (h): ");
38. scanf ("%f", &h);
39. printf ("Enter final value of x (xn): ");
40. scanf ("%f", &xn);
41. euler_method (x, y, h, xn); // Calling numerical methods
42. improved_euler (x, y, h, xn);
43. return 0;
44. }
13
Output:
14
THANKYOU

More Related Content

Similar to Euler's method 2.pptx c program for Euler's method c program for Euler's method (20)

PPTX
Runge Kutta Method Matlab Software Overview PPT
LuthfiyyahAnnisa
 
PPT
Computational techniques
Rafi Dar
 
PPTX
Initial value problems
Ali Jan Hasan
 
PDF
Ma2002 1.16 rm
Ramakrishna Paduchuri
 
PDF
Differential Calculus
OlooPundit
 
PDF
Lecture_Slides_Mathematics_06_Optimization.pdf
SantiagoGarridoBulln
 
PPS
Unit vi
mrecedu
 
PPT
Top School in india
Edhole.com
 
PPT
Chapter 3
wraithxjmin
 
DOCX
Trapezoidal Method IN Numerical Analysis
Mostafijur Rahman
 
PDF
Applied numerical methods lec12
Yasser Ahmed
 
PDF
Path relinking for high dimensional continuous optimization
Patxi Gortázar
 
PDF
_lecture_06 F_minima_maxima_classification.pdf
LeoIrsi
 
PPTX
2. Fixed Point Iteration.pptx
saadhaq6
 
PPTX
Euler Method
Saloni Singhal
 
PDF
Limits and Continuity of Functions
OlooPundit
 
PDF
Nonlinear_system,Nonlinear_system, Nonlinear_system.pdf
FaheemAbbas82
 
PDF
Term project
Mark Brandao
 
PPT
Top school in India
Edhole.com
 
PPTX
CALCULUS PRESENTATION.pptx.ecnomic and finance course
SyedHassanAbbasZaidi1
 
Runge Kutta Method Matlab Software Overview PPT
LuthfiyyahAnnisa
 
Computational techniques
Rafi Dar
 
Initial value problems
Ali Jan Hasan
 
Ma2002 1.16 rm
Ramakrishna Paduchuri
 
Differential Calculus
OlooPundit
 
Lecture_Slides_Mathematics_06_Optimization.pdf
SantiagoGarridoBulln
 
Unit vi
mrecedu
 
Top School in india
Edhole.com
 
Chapter 3
wraithxjmin
 
Trapezoidal Method IN Numerical Analysis
Mostafijur Rahman
 
Applied numerical methods lec12
Yasser Ahmed
 
Path relinking for high dimensional continuous optimization
Patxi Gortázar
 
_lecture_06 F_minima_maxima_classification.pdf
LeoIrsi
 
2. Fixed Point Iteration.pptx
saadhaq6
 
Euler Method
Saloni Singhal
 
Limits and Continuity of Functions
OlooPundit
 
Nonlinear_system,Nonlinear_system, Nonlinear_system.pdf
FaheemAbbas82
 
Term project
Mark Brandao
 
Top school in India
Edhole.com
 
CALCULUS PRESENTATION.pptx.ecnomic and finance course
SyedHassanAbbasZaidi1
 

Recently uploaded (20)

PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPT
Indian Contract Act 1872, Business Law #MBA #BBA #BCOM
priyasinghy107
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Indian Contract Act 1872, Business Law #MBA #BBA #BCOM
priyasinghy107
 
epi editorial commitee meeting presentation
MIPLM
 
Horarios de distribución de agua en julio
pegazohn1978
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Difference between write and update in odoo 18
Celine George
 
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Ad

Euler's method 2.pptx c program for Euler's method c program for Euler's method

  • 1. 1 Numerical solutions of ordinary first order differential equations by the Euler method Name : Sri Bhuvaneshwari A Register No : 34423009
  • 2. 2 Euler’s Method x0 x1 x x0 x1 x f(x) Given a differential equation y’= f (x, y) and an initial condition (x0,y0) We can approximate how the values of the function change using method f(x) error error h h
  • 3. 3 Euler’s Method • The derivative of a function y(x) represents the slope of the tangent line at any point (x, y): • For small h, we approximate this as: • This equation expresses the idea that the rate of change of y is given by the function f(x, y). • Rearranging the equation: • which gives us Euler’s method formula: where: yn​is the current value, xn​is the current step, h is the step size, f(xn,yn) is the slope at that point. = y(x+h) = y(x) + h f(x,y) yn+1​ = yn​ + h f(xn​ , yn​ )
  • 4. 4 Example • Given Differential Equation: with initial condition y(0)=1, and we want to find y(0.2) using step size h=0.1. • Solution: So, the Euler’s method approximation for y(0.2) is 1.22. S.No x y 1 0 1 2 0.1 1.1 3 0.2 1.22 Step-by-Step Calculation: Step 1: At x0 = 0, y0 = 1, f(0,1)= 0 + 1 = 1 y1​ =y0​+ h f(x0​ ,y0​ ) =1+0.1×1 = 1.1 Step 2: At x1 = 0.1, y1 = 1.1 f(0.1, 1.1) = 0.1+1.1 = 1.2 y2​= y1​+ h f(x1​ ,y1​ ) = 1.1+0.1×1.2 = 1.22 yn+1​ = yn​ + h f(xn​ , yn​ ) f(x,y) = x+y.
  • 5. 5 Improved Euler’s Method (Heun’s Method/ Euler-Cauchy Method) x0 x1 x x0 x1 x x0 x1 x x0 x1 x f(x) f(x) f(x) y1 y1 y0 y0  y’= f (x, y)  Initial condition:(x0,y0)  x1= x0+h , y1= y0 + h f(x0,y0)  m = f(x0+h , y0 + h f(x0,y0)  Average of the slopes: y1= yn+1 ​ = yn​+ ​[f(xn​, yn​ ) + f(xn+1​,ypredict ​ )]
  • 6. 6 Example • Given Differential Equation: with initial condition y(0)=1, and we want to find y(0.2) using step size h=0.1. • Solution: • So, the Improved Euler’s method approximation for y(0.2) is 1.2421. • Comparison of Results: S.No x y 1 0 1 2 0.1 1.11 3 0.2 1.2421 Step-by-Step Calculation: Step 1: At x0 =0, y0 = 1 Predict y1 ∗ ​ : y1 ∗ ​= y​ 0 + hf(0,1) =1 + 0.1×1 = 1.1 Compute f(x1,y1 ∗ ): f(0.1, 1.1) = 0.1 + 1.1 = 1.2 Corrected y1​ : y1​ = 1 + (0.1​ (1+1.2) /2) = 1 + 0.1×1.1 = 1.11 Step 2: At x1 = 0.1, y1 = 1.11 f(0.1, 1.11) = 1.21 Predict y2 ∗ ​ : y2​ ∗ = 1.11 + 0.1×1.21 = 1.231 Compute f(x2, y2 ∗ ): f(0.2, 1.231) = 0.2 + 1.231 =1.431 Corrected y2: y2​= 1.11 + (0.1​ (1.21+1.431) /2) = 1.11 + 0.1×1.3205 = 1.2421 Method y(0.2) Approximation Euler's Method 1.22 Improved Euler's Method 1.2421  y1= y0 + h f(x0,y0)  y1=
  • 7. 7 Algorithm for Euler’s Method and Improved Euler Method: • Step 1: Define the Problem = Given: 1. Initial values: x0 , y0 2. Step size: h 3. Final value of x (denoted as xn​ ) • Step 2: Euler’s Method Algorithm Euler’s method is a simple numerical approach that approximates the solution by taking small steps. 1. Start with initial values (x0 , y0). 2. Repeat until x reaches xn​ 3. Compute the next y value using the formula: ynew = y + h f (x , y ) ⋅ 4. Update x as: xnew = x + h 5. Print x, y. 6. Stop when x exceeds or reaches xn​ .
  • 8. 8 • Step 3: Improved Euler’s Method Algorithm (Heun’s Method) The Improved Euler's Method corrects the error in the basic Euler's Method by using an average slope. 1. Start with initial values (x0 ,y0). 2. Repeat until x reaches x n​ :  Compute the first slope (predictor step): k1 ​ = f (x, y)  Compute the predicted y value: y predict​= y + h k ⋅ 1​  Compute the second slope using the predicted value: k2​= f (x + h, y predict​ )  Compute the corrected y value: y new ​ = y + ​ (k ⋅ 1​ +k2​ )  Update x as: x new ​ = x + h  Print x, y. 3. Stop when x exceeds or reaches x n ​ .
  • 9. 9 • Step 4: Implement User Input Ask the user to enter 1. Initial values x0,y0 2. Step size h 3. Final value x n 4. Pass these values to both Euler’s and Improved Euler’s method functions. • Summary of the Algorithm 1. Take user input for x0, y0, h, xn​ . 2. Compute the numerical solution using Euler’s Method Use the formula ynew = y + h f(x, y). ⋅ 3. Compute the numerical solution using Improved Euler’s Method Use predictor-corrector steps. 4. Print results for both methods. Taylor Series for y(x): y(xn+1​ ) = y(xn​ ) + h y (x ′ n​ ) + ​​ y (x ′′ n​ ) + ​ y (x ′′′ n​ )+… y(xn+1​ ) ​ = y(xn​ ) ​ + h f(xn​ ,yn​ ) + ​ (​ + ​​ f(xn​ ,yn​ )) + y (x ′′′ n​ ) Heun’s Method: y(xn+1​ ) ​ = y(xn​ ) + ​[f(xn​, yn​ ) + f(xn+1​,ypredict ​ )]
  • 10. 10 C Program 1. #include <stdio.h> 2. float f(float x, float y) // Function defining the differential equation dy/dx = f(x, y) 3. { return x + y; // Example equation: dy/dx = x + y 4. } 5. void euler_method (float x, float y, float h, float xn) // Euler's Method 6. { printf ("nEuler's Method:n"); 7. printf ("xttyn"); 8. while (x <= xn) 9. { 10. printf ("%ft%fn", x, y); 11. y = y + h * f(x, y); // Euler formula 12. x = x + h; 13. } 14. }
  • 11. 11 15. void improved_euler (float x, float y, float h, float xn) // Improved Euler's Method (Heun's Method) 16. { 17. float y_predict; 18. printf ("nImproved Euler's Method:n"); 19. printf ("xttyn"); 20. while (x <= xn ) 21. { 22. printf ("%ft%fn", x, y); 23. float k1 = f(x, y); 24. y_predict = y + h * k1; // Predictor 25. float k2 = f(x + h, y_predict); 26. y = y + (h / 2) * (k1 + k2); // Corrector 27. x = x + h; 28. } 29. }
  • 12. 12 30. int main() 31. { 32. float x, y, h, xn; 33. printf ("Enter initial value of x (x0): "); // Taking user input 34. scanf ("%f", &x); 35. printf ("Enter initial value of y (y0): "); 36. scanf ("%f", &y); 37. printf ("Enter step size (h): "); 38. scanf ("%f", &h); 39. printf ("Enter final value of x (xn): "); 40. scanf ("%f", &xn); 41. euler_method (x, y, h, xn); // Calling numerical methods 42. improved_euler (x, y, h, xn); 43. return 0; 44. }