Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: Ante
  4. """
  5.  
  6. import numpy as np
  7. import matplotlib.pyplot as plt
  8. from scipy.optimize import fsolve
  9. from scipy.integrate import odeint
  10.  
  11. def f1(x):
  12. return np.sin(x)
  13.  
  14. def f2(x):
  15. return np.cos(x)
  16.  
  17. def f(x):
  18. return f1(x) - f2(x)
  19.  
  20. x = np.linspace(0, 20, 100)
  21. plt.plot(x, f1(x), 'g', label='f1')
  22. plt.plot(x, f2(x), 'r', label='f2')
  23. plt.legend()
  24.  
  25. n = []
  26. for i in range(3):
  27. n.append(fsolve(f, 3*i)[-1])
  28. n = np.array(list(set(n)))
  29. plt.scatter(n, f1(n), marker='o', color='blue')
  30.  
  31. plt.fill_between(x, f1(x), color='lightblue')
  32.  
  33. p1 = np.trapz(f1(x), x, dx=0.2)
  34. p2 = np.trapz(f2(x), x, dx=0.2)
  35. print('Razlika: ', p2-p1)
  36.  
  37. def dif_eq(z, t):
  38. return 3.2*z*np.sin(np.sqrt(z))
  39.  
  40. t = np.linspace(0, 10, 100)
  41. z = odeint(dif_eq, [10, -1], t)
  42. plt.figure()
  43. plt.plot(t, z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement