Group Abstract Group Abstract

Message Boards Message Boards

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

Define a function with a n-dimensional vector X with conditionals?

Posted 9 years ago

Dear all, I need your help in defining a function over a vector as follows.

First, I need to define a n-dimensional vector X, taking n as a variable rather than a particular value. Second, I need to define a function of X in the following way. Y(i) = 1 if i = n; Y(i) = X(i) if 1<= i <= n-1; Y(i) = 0 if i = 0.

Any suggestions? Thanks.

POSTED BY: Yong Chao
2 Replies
Posted 9 years ago

Perhaps

f[X_]:=Join[{0},Rest[Most[X]],{1}]

where

f[{1, 2, 3, 5, 7}]

returns {0, 2, 3, 5, 1}

POSTED BY: Bill Simpson
Posted 9 years ago

Thanks a lot! It helps.

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