1
$\begingroup$

I have been trying to create a certain fractal with Mathematica but the main issue is that if I try and do something like

ComplexPlot[
  Nearest[{I, -2 + I, 3 - 2 I}, z], 
  {z, -2 - 2 I, 2 + 2 I}
]

and then try to graph it, I keep getting these error messages:

Nearest::neard: The default distance function does not give a real numeric distance when applied to the point pair z and I.
Nearest::neard The default distance function does not give a real numeric distance when applied to the point pair SystemComplexPlotsDumpnz$. and I.
General::stop: Further output of Nearest::neard will be suppressed during this calculation.

I have tried doing this with normal plot and real numbers, which works just fine, and I know that nearest can handle complex numbers as it can do things like Nearest[{I + 2, 3I}, 0] and will output 2 + I. So the issue is something with ComplexPlot. The final image given is also just a red square, which is unexpected. Anyone know how to help?

New contributor
Brandon Nadel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
4
  • 1
    $\begingroup$ Perhaps an indirect approach might succeed: nf = Nearest[{I, -2 + I, 3 - 2 I}]; nfx[z_?NumericQ] := nf[z] and then try using nfx[z] instead in your plot. $\endgroup$ Jun 20 at 17:47
  • $\begingroup$ @J.M. I tried that and the errors are no longer showing up but the output it still a large red box, which shouldn't be showing up $\endgroup$ Jun 20 at 17:53
  • 1
    $\begingroup$ Ah, if you tried evaluating nfx[] at some arbitrary argument, you'd find that it gives a list and not a number. Perhaps nfx[z_?NumericQ] := First[nf[z]] is what you wanted instead? $\endgroup$ Jun 20 at 17:56
  • $\begingroup$ @J.M. that works, thanks $\endgroup$ Jun 20 at 18:01

1 Answer 1

1
$\begingroup$
Clear[ne]
ne[z_?NumericQ] := Nearest[{I, -2 + I, 3 - 2 I}, z][[1]]
ComplexPlot[ne[z], {z, -2 - 2 I, 2 + 2 I}]

enter image description here

$\endgroup$

Your Answer

Brandon Nadel is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.