Purpose:
Python Script:
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 6 21:53:43 2022
made using Spyder (anaconda3) python 3.9.12
@author: Axel4
"""
import pandas as pd
#
# slope can be a function of x
def F(x_n):
dy_dx = 2*x_n
return dy_dx
def main():
#starting position (x,y)
x_start = 0
y_start = 0
x_end = 3
h=0.01
x_n = x_start
y_n = y_start
num_steps = int((x_end - x_start)/h)
dict_x_n = {}
dict_y_n = {}
dict_F_n = {}
dict_y_n_plus_one = {}
for n in range(num_steps+1):
x_n = n*h + x_start
y_n_plus_one = y_n + h*F(x_n)
dict_x_n[n] = x_n
dict_y_n[n] = y_n
dict_F_n[n] = F(x_n, y_n)
dict_y_n_plus_one[n] = y_n_plus_one
y_n = y_n_plus_one
data = [dict_x_n, dict_y_n, dict_F_n, dict_y_n_plus_one]
df = pd.DataFrame(data, index = ['x_n', 'y_n','F_n', 'y_n+1'])
df_1 = df.transpose()
print(df_1)
main()