The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how to set initial values to symbolic variable array?
Replies: 3   Last Post: Mar 2, 2013 2:34 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Tomas Garza Hernandez

Posts: 264
Registered: 4/15/05
Re: how to set initial values to symbolic variable array?
Posted: Mar 2, 2013 2:34 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Perhaps something like this:
In[1]:= Clear[a,r]
In[2]:= Array[a,4]
Out[2]= {a[1],a[2],a[3],a[4]}
In[3]:= f=a[1]+a[2]+a[3]+a[4]
Out[3]= a[1]+a[2]+a[3]+a[4]
In[4]:= r=Table[a[j]->1,{j,1,4}]
Out[4]= {a[1]->1,a[2]->1,a[3]->1,a[4]->1}
In[5]:= f/.r
Out[5]= 4

> From:
> Subject: how to set initial values to symbolic variable array?
> To:
> Date: Wed, 27 Feb 2013 23:45:55 -0500
> 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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.