Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #pragma omp declare simd uniform(node, order)
  2. inline double lagrange(const int order, const int node, const double x)
  3. {
  4. /* Distance between nodes */
  5. const double offset = 2.0/(double)order;
  6.  
  7. /*
  8. At the specified node, l(x) = 1, and at all others l(x) = 0
  9. Use the simple form:
  10. \prod_{m, m \neq j} (x - x_m)/(x_j - x_m)
  11. */
  12. double y = 1.0;
  13. const double xj = -1.0 + ((double)node * offset);
  14.  
  15. for (int i = 0; i < order+1; i++)
  16. {
  17. const double xm = -1.0 + ((double)i * offset);
  18. if (i != node)
  19. {
  20. y *= (x - xm) / (xj - xm);
  21. }
  22. }
  23.  
  24. return y;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement