#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 15 14:07:47 2024

@author: sam
"""

import numpy as np
import matplotlib.pyplot as plt



def f(x,y):
    return x*(1+4*y**2)

def Euler(f,x0,y0,xmax,h): # function takes a function of x and y, initial x condition x0
                           # initial y condition y0, maximimum x value xmax, and step size h
    x = np.array([x0]) # creates an array of x points
    y = np.array([y0]) # creates an array of y points
    while x0 < xmax: # while within given range
        y0 += h*f(x0,y0) # Euler's method formula
        x0 += h # increase x at each step by h
        
        x = np.vstack([x,x0]) # add new x point to array of x points
        y = np.vstack([y,y0]) # add new y point to array of y points
    return x,y



x,y = Euler(f,0,0,1,0.1)

plt.plot(x,y)