Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.6K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Use SetDelayed for a selected set of indices?

Posted 9 years ago

I'm trying to define some delayed values and let mathematica do the simplification for me during the course of computation. Here is a minimal work example:

x[i_] := y[i];
Mx = Table[x[i] + 2, {i, 1, 10}];
My = Table[y[i], {i, 1, 10}];
difference = Mx - My

The output is simply {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}. What I'm eager to know is if there is a way that I can define the delayed value only for x[i] with 2<=i<=10 (i.e. a selected subset of the indices), so that the final result would be something like {x[1]-y[i]+2, 2, 2, 2, 2, 2, 2, 2, 2, 2}. That is, every entry of the result is reduced by taking the delayed values but the first one. Thanks!!

POSTED BY: K X
2 Replies
Posted 9 years ago

Thanks!! This is exactly what I need. /; condition is really really useful for me.

POSTED BY: K X

SetDelayed for a selected set of indices

How about doing exactly this!

ClearAll["Global`*"]
x[i_ /; i > 1] := y[i];
Mx = Table[x[i] + 2, {i, 1, 10}]
My = Table[y[i], {i, 1, 10}]
difference = Mx - My
POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard