Guest User

Untitled

a guest
Nov 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import math
  2. def eule(f,a,b,xa,n):
  3. t = a
  4. x = xa
  5. h = (b-a)/n
  6. while t < b :
  7. x += h * f(x,t)
  8. t += h
  9. print('the approx solu is x =', b,'is',x)
  10.  
  11. #3a
  12. def f(x,t):
  13. return x
  14. eule(f, 0, 1, 1, 1)
  15. eule(f, 0, 1, 1, 2)
  16. print('\n')
  17.  
  18.  
  19. #3b
  20. def eule1(f,a,b,xa,n):
  21. t = a
  22. x = xa
  23. h = (b-a)/n
  24. while t < b:
  25. x += h * f(x,t)
  26. t += h
  27. print(' the approx solu is x =', b,'is',x,'and the abs error is',2.41287593875817 - x)
  28.  
  29. def g(x,t):
  30. return t + math.sin(x)
  31. eule1(g, 0, 1, 1, 5)
  32. eule1(g, 0, 1, 1, 25)
  33. eule1(g, 0, 1, 1, 125)
  34. eule1(g, 0, 1, 1, 625)
  35. print('\n')
  36.  
  37. # 3c
  38. def y(x,t):
  39. return .001*x*(900-x)
  40. eule(y, 0, 1, 200, 100)
  41. print('\n')
  42.  
  43. def tay2de(f, fp, a, b, xa, n):
  44. t = a
  45. x = xa
  46. h = (b-a)/n
  47. while t< b:
  48. x += h *f(x,t) + ((h**2)/2) * fp(x,t)
  49. t += h
  50. print(' the approx value of sol at x =',b,'is',x)
Add Comment
Please, Sign In to add comment