Re: linear equations with indexed variables?
- To: mathgroup at smc.vnet.net
- Subject: [mg6940] Re: [mg6896] linear equations with indexed variables?
- From: "w.meeussen" <w.meeussen.vdmcc at vandemoortele.be>
- Date: Tue, 29 Apr 1997 20:48:19 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
At 14:00 25-04-97 -0400, 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 > > For larger (or unbounded) ranges of i, use the add-on package provided: In[1]:= <<DiscreteMath`RSolve` In[2]:= RSolve[ {3x[i] == 2x[i+1] + x[i-1] ,x[4 ] == 1, x[0] == 0},x[i],i] Solve::"svars": "Equations may not give solutions for all \"solve\" variables." Out[2]= 4 - i {{x[i] -> 2 + 2 (-1 + C[1]) - C[1] + 14 If[i == 0, 1, 0] - 15 C[1] If[i == 0, 1, 0] - (-6 + 7 C[1] - C[3]) If[i == 1, 1, 0] - (-2 + 3 C[1] - C[2]) If[i == 2, 1, 0]}} ***** the occurence of undetermined constants C[..] shows that the eqn is underdetermined, the profusion of "If[i=..,..,..]" shows it is not "simple" or "clean". ***** In[6]:=Table[{i,x[i]/.%2},{i,0,10}]//Simplify Out[6]= {{0, {0}}, {1, {C[3]}}, {2, {C[2]}}, {3, {C[1]}}, {4, {1}}, 1 1 {5, {- (3 - C[1])}}, {6, {- (7 - 3 C[1])}}, 2 4 1 1 {7, {- (15 - 7 C[1])}}, {8, {-- (31 - 15 C[1])}}, 8 16 1 1 {9, {-- (63 - 31 C[1])}}, {10, {-- (127 - 63 C[1])}}} 32 64 why not play 'round with the package, and see what it can do for you. Dr. Wouter L. J. MEEUSSEN eu000949 at pophost.eunet.be w.meeussen.vdmcc at vandemoortele.be