Here is some example code in the order of contour, euler method, and slope field
ID: 3847160 • Letter: H
Question
Here is some example code in the order of contour, euler method, and slope field.
Explanation / Answer
# FB - 201104096
import science
# initial Order lyric (y' = f(x, y)) problem solver victimization mathematician methodology
# xa: initial price of experimental variable
# xb: final price of experimental variable
# ya: initial price of variable quantity
# n : variety of steps (higher the better)
# Returns price of y at xb.
def Euler(f, xa, xb, ya, n):
h = (xb - xa) / float(n)
x = xa
y = ya
for i in range(n):
y += h * f(x, y)
x += h
return y
# Second Order lyric (y'' = f(x, y, y')) problem solver victimization mathematician methodology
# y1a: initial price of calculation of variable quantity
def Euler2(f, xa, xb, ya, y1a, n):
h = (xb - xa) / float(n)
x = xa
y = ya
y1 = y1a
for i in range(n):
y1 += h * f(x, y, y1)
y += h * y1
x += h
return y
if __name__ == "__main__":
print Euler(lambda x, y: math.cos(x) + science.sin(y), 0, 1, 1, 1000)