Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def eule(f,a,b,xa,n):
- t = a
- x = xa
- h = (b-a)/n
- while t < b :
- x += h * f(x,t)
- t += h
- print('the approx solu is x =', b,'is',x)
- #3a
- def f(x,t):
- return x
- eule(f, 0, 1, 1, 1)
- eule(f, 0, 1, 1, 2)
- print('\n')
- #3b
- def eule1(f,a,b,xa,n):
- t = a
- x = xa
- h = (b-a)/n
- while t < b:
- x += h * f(x,t)
- t += h
- print(' the approx solu is x =', b,'is',x,'and the abs error is',2.41287593875817 - x)
- def g(x,t):
- return t + math.sin(x)
- eule1(g, 0, 1, 1, 5)
- eule1(g, 0, 1, 1, 25)
- eule1(g, 0, 1, 1, 125)
- eule1(g, 0, 1, 1, 625)
- print('\n')
- # 3c
- def y(x,t):
- return .001*x*(900-x)
- eule(y, 0, 1, 200, 100)
- print('\n')
- def tay2de(f, fp, a, b, xa, n):
- t = a
- x = xa
- h = (b-a)/n
- while t< b:
- x += h *f(x,t) + ((h**2)/2) * fp(x,t)
- t += h
- print(' the approx value of sol at x =',b,'is',x)
Add Comment
Please, Sign In to add comment