Write a function for Euler methods with python. Then find and
write a test to prove the code is right.
# Following is a Python Program to find approximation of
# an ordinary differential equation
# using Euler method.
# Let us Consider a differential equation
# dy / dx =(x + y + xy)
def func( x, y ):
return (x + y + x * y)
# Function for Euler Expression
def Euler( x0, y, h, x ):
temp = -0
# Scanning till that point where we need approximation
while x0 < x:
temp = y
y = y + h * func(x0, y)
x0 = x0 + h
# Now Displaying Approximation
print("Approximate solution at x = ", x, " is ", "%.6f"% y)
# Driver Code to test
x0 = 0
y0 = 1
h = 0.025
# Value of x where we need approximation
x = 0.1
Euler(x0, y0, h, x)
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.