Group Abstract Group Abstract

Message Boards Message Boards

0
|
10.1K Views
|
9 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Using ReplaceAll (/.) with complex variables?

Posted 10 years ago
POSTED BY: Paul Hillman
9 Replies
Posted 10 years ago

Without any disrespect, whats the fuzz? The OP's replacements does seem to work (provided there is a space left between I and the variable symbol):

In[1]:= test = {{a + I b, b + I c}, {d + I e, e + I f}}

Out[1]= {{a + I b, b + I c}, {d + I e, e + I f}}

In[2]:= test /. {e -> 1, f -> 2}

Out[2]= {{a + I b, b + I c}, {I + d, 1 + 2 I}}
POSTED BY: Hans Milton
POSTED BY: Sander Huisman

This is not the whole story. ReplaceAll (and related functions) use the FullForm for pattern matching, and to replace a part of the complex number one needs to use this form. It is true that 3 + 4 I is atomic but one may use the head of this expression to get into its parts

FullForm[3 + 4 I]

returns

Complex[3,4]

therefore

3+ 4 I /. Complex[x_,4]:> Complex[x,12]

returns

3 + 12 I

as expected

You could've noticed it from the coloring already; unknown symbols are blue (or green inside e.g. Module) (a,b,c,d,e,f), known symbols are black (I)....

Note that you can't use replace(all) on complex numbers:

3 + 4 I /. 4 -> 5

as they are treated as an 'atom', so it will just return 3 + 4I.

POSTED BY: Sander Huisman

Sorry about the coloring, don't really know how that happened. a,b,c,d,e,f were suppose to be unknown symbols.

POSTED BY: Paul Hillman

That is not your fault, that is caused because you need a space between symbols:

If
Ie

versus

I f
I e
POSTED BY: Sander Huisman
Posted 10 years ago

Hint:

Ie

is a single symbol.

I*e

or

I e

is the product of two things.

2I

or

2*I

or

2 I

also happen to be the product of two things.

That should be enough.

POSTED BY: Bill Simpson

Thanks Bill, for some reason I thought that I was reserved, so Ie and If would be a product to two things.

POSTED BY: Paul Hillman
Posted 10 years ago

Your thinking that I is reserved is correct, but that isn't sufficient to override the principle that anything beginning with a letter followed by any number of letters and digits will be considered to be one symbol. This kind of problem shows up again and again and again and again...

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