DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptxBanyMacalintal
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:
ynis the current value,
xnis 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
)]
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. }