Re: linear equations with indexed variables?
- To: mathgroup at smc.vnet.net
- Subject: [mg6931] Re: linear equations with indexed variables?
- From: Eugene Lee <elee at aw.sgi.com>
- Date: Tue, 29 Apr 1997 20:48:12 -0400 (EDT)
- Organization: Alias Wavefront
- 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 Using the boundary conditions, your system is a matrix equation: A.X == b, where for your example, A={{-3,2,0},{1,-3,2},{0,1,-3}}; b={0,0,-2}; Let X=Array[x,3], then you just use Solve: In[64]:= Solve[A.X==b, X] Out[64]= 8 14 4 {{x[1] -> --, x[3] -> --, x[2] -> -}} 15 15 5 YIf the range of i is large, no problem arises, since the matrix is tridiagonal and has the same pattern. Eugene Lee