Code: Select all
def function(x, y, h):
derivalue = float(eval(dydx))
print("|| "+str(round(x ,2))+" || "+str(round(y ,2))+" || "+str(round(derivalue ,2))+" || "+str(round(x+h ,2))+" || "+str(round(y+(derivalue*h) ,2))+" ||")
global xCoord
global yCoord
xCoord = x + h
yCoord = y+(derivalue*h)
iterations = int(input("Iterations: "))
xCoord = float(input("Initial x coordinate: "))
yCoord = float(input("Initial y coordinate: "))
hSteps = float(input("Step size: "))
dydx=input("dy/dx=")
print("==============================================")
print("|| X || Y || dy/dx || x+h || y+(dy/dx)h ||")
print("==============================================")
for i in range(iterations):
function(xCoord, yCoord, hSteps)
Code: Select all
Iterations: 4
Initial x coordinate: 1
Initial y coordinate: 1
Step size: 0.5
dy/dx=x**2 + y**2
Code: Select all
===========================
|| X || Y || dy/dx || x+h || y+(dy/dx)h ||
===========================
|| 1.0 || 1.0 || 2.0 || 1.5 || 2.0 ||
|| 1.5 || 2.0 || 6.25 || 2.0 || 5.12 ||
|| 2.0 || 5.12 || 30.27 || 2.5 || 20.26 ||
|| 2.5 || 20.26 || 416.63 || 3.0 || 228.57 ||
Code: Select all
===========================
|| X || Y || dy/dx || x+h || y+(dy/dx)h ||
===========================
Traceback (most recent call last):
File "<stdin>", line 20, in <module>
File "<stdin>", line 2, in function
File "<string>", line 1, in <module>
NameError: name 'x' is not defined