MathGroup Archive 1997

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

Search the Archive

Re: linear equations with indexed variables?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6930] Re: linear equations with indexed variables?
  • From: Daniel Lichtblau <danl>
  • Date: Tue, 29 Apr 1997 20:48:12 -0400 (EDT)
  • Organization: Wolfram Research, Inc.
  • Sender: owner-wri-mathgroup at wolfram.com

Hong-liang Xie wrote:
> 
> I am new to Mathematica and I need to solve a system of
> linear equations whose variables are indexed (i.e., x[1],
> x[2], x[3]), for example,
> 
>        3x[i] = 2x[i+1] + x[i-1] ( 1 <= i <= 3)
>        x[4 ]  = 1
>        x[0]   = 0
> 
> The above is a system of 5 linear equations with
> 5 variables x[0], x[1], x[2], x[3], x[4].  I can certainly
> rewrite it into 5 equations using 5 variables x0, x1, x2,
> x3, x4.  However, if the range of i gets bigger, or, worse,
> if each x has two indexes as in x[i,j], this rewriting could
> get of hand quickly.  I tried different equation solving
> functions in Mathematica but with no luck.  I would therefore
> appreciate help from experts here on how to solve this kind of
> equations directly.  Thanks a lot!
> 
> Hong
> CIS Dept
> Univ of Pennsylvania

You might do it as below. The code can be condensed, but I show it
step-by-step to make modification easier.

In[10]:= vars = Array[x, 5, 0];

In[11]:= endEqns = {x[0] == 0, x[4] == 1};

In[12]:= middleEqns = Table[3*x[j] == 2*x[j+1] + x[j-1], {j, 3}];

In[13]:= eqns = Join[middleEqns, endEqns];

In[14]:= InputForm[Solve[eqns, vars]]
Out[14]//InputForm= 
  {{x[0] -> 0, x[1] -> 8/15, x[2] -> 4/5, x[3] -> 14/15, x[4] -> 1}}


Daniel Lichtblau
Wolfram Research
danl at wolfram.com


  • Prev by Date: Re: linear equations with indexed variables?
  • Next by Date: Re: linear equations with indexed variables?
  • Previous by thread: Re: linear equations with indexed variables?
  • Next by thread: Re: linear equations with indexed variables?