I am currently enjoying writing computational codes as a hobby. Right now I've worked out an Euler method and results are pretty good with up to $x=1$. Over $x=1$, instability starts to kick in. May I know why is this so? The equations are as below: $$ df=-\frac{x^2}{y},\quad y(0)=1 $$
#Euler Method
import numpy as np
import matplotlib.pyplot as plt
#Specify Step Size:
h=float(input("Size of h:"))
#Key in X value you want to obtain y(x1):
x1=float(input("input X to get Y:"))
#Number of steps:
n=int((x1)/h)+1
#Creation of array table
A=np.zeros((n,3))
A[0]=[1,0,1]
for i in range(1,n):
#Evaluating values of y:
A[i,0]=i+1
df=-(A[i-1,1]**2)/A[i-1,2]
A[i,2]=A[i-1,2]+h*df
A[i,1]=A[i-1,1]+h
print(A)
plt.plot(A[:,1], A[:,2], label='Approximation')
plt.show()