Message Boards Message Boards

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

Adding definitions to a function

Posted 9 years ago

Hi, Suppose I start with a simple function : F I need to set F[k] equal to 0 for some k values. For a single value, the following instructions do the job (Version 8.0) :

Clear[F]; F[x_] := 1; F[1] := 0;
Table[F[k], {k, 10}]
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1}

However for a lot of values (say belonging to a lengthy list) the following doesn't work :

Clear[F]; list = {1, 2, 3}; F /@ list := 0;
SetDelayed::write: Tag Map in F/@{1,2,3} is Protected. >>

Any idea about by what to write in place of F /@ list := 0; ? Thanks in advance Andre

POSTED BY: Andre Hautot
2 Replies
Posted 9 years ago

The first solution is perfect, thanks a lot !

POSTED BY: Andre Hautot

One way:

Clear[f];
Map[(f[#] = 0) &, {1, 2, 3}]

Another way:

Clear[f];
list = {1, 2, 3};
Do[f[i] = 0, {i, list}]
POSTED BY: Gianluca Gorni
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