Message Boards Message Boards

0
|
5576 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Avoid nonatomic expression error message?

Posted 5 years ago

This code produces a correct result, but gives an error message:

Clear[l, CI]

2 CI[{{2, 2}}] + 2 CI[{{1, 2}, {2, 1}}] /. CI[l_] -> j^(Total[l][[2]])

Total::normal: Nonatomic expression expected at position 1 in Total[l].

Part::partw: Part 2 of Total[l] does not exist.

2 j^2 + 2 j^3

Is there an easy way to eliminate the error message?

POSTED BY: Robert Russell

Use RuleDelayed instead of Rule:

In[236]:= 2 CI[{{2,2}}]+2 CI[{{1,2},{2,1}}]/.CI[l_]:>j^(Total[l][[2]])

Out[236]= 2 j^2+2 j^3
POSTED BY: Robert Nachbar
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract