We have the following mathematical formulas to solve differential equations by Euler's method
xn+1 = xn + h
yn+1 = yn + h*f(xn, yn)
Suppose we have been provided y(x0)=any value,then we have x0 and y0 and also h has been provided by the user.
I am having problem to understand how can I accept the function f(xn, yn) from the user since the function can be either algebraic,trigonometric,exponential or logarithmic and the function would be of type dy/dx=(expression).The program code should be able to solve any differential expression entered by the user and the answers of the approximations must be correct upto 4 decimal places.
It is possible to accept the expression as a String but I would not be able to perform calculations on String.Any suggestions or solutions would be appreciated.
Site of Euler's method:http://calculuslab.deltacollege.edu/ODE/7-C-1/7-C-1-h-c.html
Example Input:
expression input:
dy/dx=x+2y
initial conditions input:
x0=0, y0=0
enter step size: h=0.25
enter the value for which you want to find solution for: x=1
Example output: