Re: linear equations with indexed variables?

*To*: mathgroup at smc.vnet.net*Subject*: [mg6963] Re: [mg6896] linear equations with indexed variables?*From*: jpk at max.mpae.gwdg.de*Date*: Wed, 30 Apr 1997 22:25:23 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

> From hxie at gradin.cis.upenn.edu Fri Apr 25 23:44:18 1997 > Date: Fri, 25 Apr 1997 14:00:30 -0400 (EDT) > From: hxie at gradin.cis.upenn.edu (Hong-liang Xie) > To: mathgroup at smc.vnet.net > Subject: [mg6896] linear equations with indexed variables? > > 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 > > > > > > Hi Hong, You had a system of recurence equations with constant coeficients and a boundary problem for this system. The recurence equations with constant coefficients can be solved usualy by the ansatz x(i)=zeta^i. By insertion of this ansatz in Your recurence equation You get the two solutions zeta=1/2 and zeta=1. This step looks in Mathematica 3.0 so In[1]:= fdeqn=3 x[i]==2 x[i+1]+x[i-1]; In[2]:= fdsol=Solve[ Cancel[\[Zeta]^(-i)*#] & /@ (fdeqn /. x[i_]:>\[Zeta]^i), \[Zeta] ] Out[2]= {{\[Zeta] -> 1/2}, {\[Zeta] -> 1}} With this solutions for zeta You can construct the general solution of Your recurence equation as x[i]=C[1]*zeta[1]^i+C[2]*zeta[2]^i The two arbitary constants C[1] and C[2] must be determined from the boundary conditons. We make our solution a bit more Mathematica like with In[3]:= sol=x[i_]:> Evaluate[Plus @@(Map[Apply[Times,#] &, Transpose[{{C[1],C[2]},\[Zeta] ^i/.fdsol}]])] Out[3]= x[i_] :> C[1]/2^i + C[2] Now lets determine C[1] and C[2] In[4]:= boundsol=Solve[bound={x[4]==1,x[0]==0} /. sol,{C[1],C[2]}] Out[4]= {{C[1] -> -(16/15), C[2] -> 16/15}} Now one gets the final solution for Your equations with In[5]:= finalsol= First[x[i] /. sol /.boundsol] Out[5]=16/15 - 2^(4 - i)/15 That's all. Hope that helps Jens