<jupyter_start><jupyter_text>Euler method<jupyter_code># This is a standard initalisation code - no need to change this
# It loads basic fast array code, plot library and ODE solver
import math
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
%matplotlib inline
%config InlineBackend.figure_formats={'retina','png'}
def f(t, x):
    return x
## initial time and position
t = 0
tmax = 2
x = 1

## step
h = 0.2

## Lists to store the solution, and store thed initial point
ti = [t]
xi = [x]

while t < tmax:
    x = x+h*f(t, x)
    t = t+h
    xi.append(x)
    ti.append(t)

print("ti=", ti)
print("xi=", xi)
fig, ax = plt.subplots(1)

ax.scatter(ti, xi, label="Euler")
ax.set_xlabel("$t$")
fig.legend()

xexact = np.exp(ti)

ax.plot(ti, xexact, label="Exact solution")
fig.legend()
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13466042154566746, 'fraction_numerical': 0.00702576112412178, 'mean_word_length': 4.3105590062111805, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '454862', 'license': 'MIT', 'n_tokens_mistral': 347, 'n_tokens_neox': 339, 'n_words': 104, 'path': 'Euler.ipynb', 'repo_name': 'fedxa/PHYS30471', 'size': '854'}