Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This program attempts to approximate the value of
- the mathematical constant e, which is about 2.718
- This method uses Euler's method for solving
- differential equations to approximate the function
- defined by the differential equation dy/dx = y,
- which if solved analytically is e^x. So, as x
- approaches 1, we get closer and closer to e.
- With xStep at 0.00001, it is accurate to 4 decimals
- While there are much better and more accurate ways
- to calculate e, this is most likely the simplest.
- ]]
- local xStep = 0.00001 -- Smaller = more accurate
- -- Give the initial condition, when x = 0, y = 1
- local ypos = 1
- local lslope = 1
- for i=1, 1/xStep do
- ypos = ypos + (lslope)*xStep
- lslope = ypos
- end
- print(ypos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement