Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.9K Views
|
8 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Dynamic locator with a complex number

Posted 4 years ago
POSTED BY: Ehud Behar
8 Replies
Posted 4 years ago

Murray Eisenberg and Rohit Namjoshi, Thanks a lot for all of your comments.

POSTED BY: Ehud Behar
Posted 4 years ago

Hi Ehud,

Do you mean something like this?

DynamicModule[{p = {0.5, 0.5}}, {Graphics[Locator[Dynamic[p]], PlotRange -> 2], 
  Dynamic[Complex[Sequence @@ p]]}]

BTW, was my answer to your earlier question helpful?

POSTED BY: Rohit Namjoshi

That's nice!

It seems to me there ought to be a built-in function, say ToComplex, that does what Complex[Sequence @@ #]& does. This would be an inverse to the built-in function ReIm.

This just seems such a basic thing to have. Something that even beginners could make sense of, as opposed to Sequence @@ p, that is, Apply[Sequence, p], which involve two non-elementary programming constructs, Apply and Sequence.

POSTED BY: Murray Eisenberg
Posted 4 years ago

I looked up the net and the documentation and couldn't find a built in function to this type of conversion. I would be glad to get to know a simple way for doing it.

POSTED BY: Ehud Behar
Posted 4 years ago

Hi Murray,

I was being dumb, easier way

Complex @@ {0.5, 0.5}
(* 0.5 + 0.5 I *)

toComplex = Complex @@ # &

toComplex[{0.5, 0.5}]
toComplex@{0.5, 0.5}
POSTED BY: Rohit Namjoshi

Perhaps better to overload like this:

toComplex[xy_] := Complex @@ xy
toComplex[x_, y_] := Complex[x, y]

Then one can do, for example, both the following...

toComplex[{3, 4}]
toComplex[3, 4]

... and get the same result.

POSTED BY: Murray Eisenberg
Posted 4 years ago
POSTED BY: Ehud Behar

Ehud, Alas, the Mathematica developers, including Stephen Wolfram, have never really come to grips with complex numbers as basic objects to use in Graphics — even though Complex is not only a built-in type and even though by default many functions assume their arguments are complex rather than real.

POSTED BY: Murray Eisenberg
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard