Re: linear equations with indexed variables?
- To: mathgroup at smc.vnet.net
- Subject: [mg6934] Re: linear equations with indexed variables?
- From: sherod at boussinesq.Colorado.EDU (Scott Herod)
- Date: Tue, 29 Apr 1997 20:48:14 -0400 (EDT)
- Organization: /usr/local/lib/rn/organization
- Sender: owner-wri-mathgroup at wolfram.com
Just off the bat, you could easily convert your equations to a full
system using something like
====================================================================
In[1]:=
eqns = Table[3 x[i] == 2 x[i+1] + x[i-1], {i,1,3}]
Out[1]=
{3 x[1]==x[0]+2 x[2],3 x[2]==x[1]+2 x[3],3 x[3]==x[2]+2 x[4]}
In[2]:=
moreEqns = Flatten[Union[eqns, {x[0] == 0, x[4] == 1}]]
Out[2]=
{x[0]==0,3 x[1]==x[0]+2 x[2],3 x[2]==x[1]+2 x[3],3 x[3]==x[2]+2 x[4],x[4]==1}
In[3]:=
Solve[%]
======================================================================
But I notice that you are solving a difference equation with a pair
of boundary conditions. It might be easier to do something like the
following if this is always the case.
====================================================================
In[1]:= x[i_] := r^i
In[3]:= Factor[3 x[i] - 2 x[i+1] - x[i-1]]
-1 + i
Out[3]= -((-1 + r) r (-1 + 2 r))
In[4]:= Solve[% == 0, r]
Solve::ifun: Inverse functions are being used by Solve, so some solutions may
not be found.
1 1/(-1 + i)
Out[4]= {{r -> -}, {r -> 1}, {r -> 0 }}
2
(* I need to figure out a slick way to get rid of the r^(i-1) term. *)
In[9]:= y[i_] := (C[1] x[i] /. Out[4][[1]]) + (C[2] x[i] /. Out[4][[2]])
In[10]:= y[i]
C[1]
Out[10]= ---- + C[2]
i
2
In[11]:= Solve[{y[0] == 0, y[4] == 1}]
16 16
Out[11]= {{C[1] -> -(--), C[2] -> --}}
15 15
=======================================================================
Scott Herod
Applied Math
Univ. of Colorado, Boulder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In article <5jqr2i$hb8 at smc.vnet.net> hxie at gradin.cis.upenn.edu (Hong-liang Xie) writes:
>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
>
>
>
>
>
>