Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. pts = {{-0.2, -0.2}, {0.2, 0.2}};
  2. NIntegrate[Nearest[pts-> "Distance", {x, y}] , {x, y} [Element] Disk[]]
  3. (*Nearest: The default distance does not give a real numeric distance when
  4. applied to the point pair {x,y} and {-0.2,-0.2}.*)
  5.  
  6. pts = {{-0.2, -0.2}, {0.2, 0.2}};
  7. Block[{f, nf},
  8. nf = Nearest[pts -> "Distance"]; (* precompute NearestFunction *)
  9. f[x_?NumericQ, y_?NumericQ] := (* NumericQ prevents evaluation on symbolic x, y *)
  10. First@nf[{x, y}]; (* Nearest returns a list; extract distance with First *)
  11. NIntegrate[f[x, y], {x, y} ∈ Disk[]]
  12. ]
  13. (* 1.69082 *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement