SHARE
TWEET

2016BC2.py

calcpage Jun 23rd, 2016 710 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. #MrG 2016.0623 2016BC2
  3. #2a) x(3)=14.377, y(3)=-0.5
  4. from math import sin, sqrt
  5.  
  6. def f(t):
  7.     return t**2+sin(3*t**2)
  8.  
  9. print "x(3) = "
  10. a=float(0)
  11. b=float(3)
  12. for x in range(5):
  13.     n=10**x
  14.     h=(b-a)/n
  15.     l=sum([f(a+i*h)*h for i in range(n)])
  16.     r=l-f(a)*h+f(b)*h
  17.     print 5+(l+r)/2
  18.  
  19. #2b) dy/dx=0.050 when t=3
  20. print
  21. print "dy/dx when t is 3 = ", 0.5/f(3)
  22.  
  23. #2c) abs(v(3))=9.969
  24. print
  25. print "abs(v(3)) = ", sqrt(f(3)**2+0.5**2)
  26.  
  27. #2d) l=4.350
  28. def g(t):
  29.     return sqrt(f(t)**2+4)
  30.  
  31. print
  32. print "l1 = "
  33. a=float(0)
  34. b=float(1)
  35. for x in range(5):
  36.     n=10**x
  37.     h=(b-a)/n
  38.     l=sum([g(a+i*h)*h for i in range(n)])
  39.     r=l-g(a)*h+g(b)*h
  40.     l1=(l+r)/2
  41.     print l1
  42.  
  43. def g(t):
  44.     return sqrt(f(t)**2)
  45.  
  46. print
  47. print "l2 = "
  48. a=float(1)
  49. b=float(2)
  50. for x in range(5):
  51.     n=10**x
  52.     h=(b-a)/n
  53.     l=sum([g(a+i*h)*h for i in range(n)])
  54.     r=l-g(a)*h+g(b)*h
  55.     l2=(l+r)/2
  56.     print l2
  57.    
  58. print
  59. print "l1+l2 = ", l1+l2
RAW Paste Data
Top