MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to set initial values to symbolic variable array?


Look up Pattern and Blank

f = Total[Array[a, 4]]

a[1] + a[2] + a[3] + a[4]

f /. a[_] -> 1

4

f /. a[n_] -> n

10


Bob Hanlon


On Wed, Feb 27, 2013 at 11:45 PM, Jon <devout1977 at gmail.com> wrote:
>
> Dear All,
>
> Suppose I defined a symbolic variable array as
>
> Array[a,4]
>
> and defined a function as
>
> f = a[1] + a[2] + a[3] + a[4]
>
> I need to evaluate the value of f in the following way,
>
> f/.{a[1]->1,a[2]->1, ...}
>
> but specify each element of the array one by one is very troublesome, and I
> wonder whether there is something like a group definition like
>
> f/.{a[1:4]->1}
>
> to define the four variables at the same time with the same value.
>
> Thanks for your help,
>
> Sincerely,
> John
>
>



  • Prev by Date: Re: Odd edge-case behavior of Block
  • Next by Date: Re: Legends for Data Plots
  • Previous by thread: Re: how to set initial values to symbolic variable array?
  • Next by thread: Re: how to set initial values to symbolic variable array?