-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheulersolver.py
More file actions
81 lines (76 loc) · 2.8 KB
/
eulersolver.py
File metadata and controls
81 lines (76 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Created by Spencer Boggs
import math
print("")
print(" Welcome to Euler's")
print(" Method Solver!")
print(" Created by Spencer Boggs")
print("")
print(" Remember to use proper syntax")
print(" Use parenthesis for complex")
print(" fractions and fractional")
print(" expressions. Please convert")
print(" cx to c*x when entering dy/dx")
print(" Use ** for exponents (x**2)")
print("")
input(" Press [Enter] to Start")
while True:
print("")
e = 2.7182818284
y = input("Enter a y value: ")
try: float(y)
except ValueError: y = None;
if (y != None):
y = float(y)
x = input("Enter a x value: ")
try: float(x)
except ValueError: x = None;
if (x != None):
x = float(x)
stepCount = input("Number of steps: ")
stepSize = input("Enter step size: ")
derivative = input('Enter dy/dx: ')
try: eval(derivative)
except SyntaxError: derivative = None
if (derivative != None):
try: eval(derivative)
except NameError: derivative = None
if (derivative != None):
if (str(y)) and (str(x)) and (stepCount) and (stepSize) and (derivative):
x = float(x)
y = float(y)
print('')
for i in range(int(stepCount)):
m = eval(derivative)
print("---- Step " + str(i+1) + " ----")
print("Slope: " + str(m))
print("y - " + str(y) + " = " + str(m) + "(x - " + str(x) + ")")
initialEquation = (str(m) + ' * x + ' + str(eval('(-x*m)+y')))
x = x+float(stepSize)
y = eval(str(initialEquation))
print('Tangent Line Equation ' + str(i + 1) + ': y = ' + str(initialEquation))
print("Y Coordinate after " + str(i+1) + " step(s): " + str(y))
print("Coordinates: (" + str(x) + ", " + str(y) + ")")
print('')
if (int(i+1) < int(stepCount)):
a = input("Press [Enter] to go to step " + str(i+2))
elif (int(i+1) == int(stepCount)):
a = input("Press [Enter] to proceed")
print('')
else:
print('')
print('Unsolvable. Double check')
print('your inputs.')
else:
print('')
print('Please enter a valid')
print('equation. Enter any')
print('multiplication with *')
print('Ex: cx -> c*x')
input("Press [Enter] to proceed")
else:
print('')
print('Please enter a valid')
print('equation. Enter any')
print('multiplication with *')
print('Ex: cx -> c*x')
input("Press [Enter] to proceed")