Euler Method for solving differential equation | Java program to find approximation of an ordinary differential equation using euler method ; Consider a differential equation dy / dx = ( x + y + xy ) ; Function for Euler formula ; Iterating till the point at which we need approximation ; Printing approximation ; Driver program ; Initial Values ; Value of x at which we need approximation
import java . io . * ; class Euler { float func ( float x , float y ) { return ( x + y + x * y ) ; } void euler ( float x0 , float y , float h , float x ) { float temp = - 0 ; while ( x0 < x ) { temp = y ; y = y + h * func ( x0 , y ) ; x0 = x0 + h ; } System . out . println ( " Approximate ▁ solution ▁ at ▁ x ▁ = ▁ " + x + " ▁ is ▁ " + y ) ; } public static void main ( String args [ ] ) throws IOException { Euler obj = new Euler ( ) ; float x0 = 0 ; float y0 = 1 ; float h = 0.025f ; float x = 0.1f ; obj . euler ( x0 , y0 , h , x ) ; } }