euler_tut.py

Created by vnap0v

Created on August 12, 2025

661 Bytes

Euler’s method using Python

On the English YouTube channel of Numworks, there is a tutorial on using the sequences app to apply Euler’s method on a differential equation:

Euler’s method using sequences

This script does the same calculations, using Python instead.

The differential equation:

dy/dx = sqrt(x) * y
y(1) = 4

For Euler’s method step h=0.25

Tested on the Numworks calculator using software version 24.3.0


# Python version of Euler's method
# originally using the sequence app
# in Numworks tutorial
# https://youtu.be/JIc2p6jtGhs?si=QwTqrjLIRexZK6hJ
from math import *
# parameters
h=0.25 # x step
x_init=1 # initial values
y_init=4
n_iter=8 # number of steps

# function defines differential
# equation by returning value
# of derivative of y
def dy_dx(x,y):
    value_dy_dx=sqrt(x)*y
    return value_dy_dx

x=x_init # start with initial values
y=y_init
print("{0:<6} {1:<10}".format("x","y"))
print("-"*10)
for _ in range(n_iter):
    print("{0:<6} {1:<10.10f}".format(x,y))
    # calculate new y value using Euler
    y+=dy_dx(x,y) * h
    x+=h

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.