MathGroup Archive 2001

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

Search the Archive

RE: Re: RE: Solving for Sum element

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27275] RE: [mg27292] Re: [mg27270] RE: [mg27260] Solving for Sum element
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 18 Feb 2001 02:52:11 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

I like Mark's solution a lot because it is quite transparent and
controllable in it's usage.

I couldn't resist touching it up slightly to prevent long sums of terms
before the substitution stage.

solveElement[eqn_, k_] := (
      sum1 = ReplacePart[HoldForm @@ {eqn[[1]]}, k - 1, {1, 2, 3} ];
      sum2 = ReplacePart[HoldForm @@ {eqn[[1]]}, k + 1, {1, 2, 2} ];
      Rule[Part[ReplacePart[eqn, k, {1, 1, 1} ], 1, 2],
        Part[eqn, 2] - (sum1 + sum2) ]  );

eqn2 = Sum[a[i], {i, 1, N}] == 25.

solveElement[eqn2, 30]
% /. {N -> Infinity, a[30] -> x, a[i_] -> E^-i}
% // ReleaseHold

a[30] -> 25. - HoldForm[Sum[a[i], {i, 1, 29}]] -
   HoldForm[Sum[a[i], {i, 31, N}]]

x -> 25. - HoldForm[Sum[E^(-i), {i, 1, 29}]] -
   HoldForm[Sum[E^(-i), {i, 31, Infinity}]]

x -> 24.418

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



> From: Mark Harder [mailto:harderm at ucs.orst.edu]
To: mathgroup at smc.vnet.net
>
> David Park seems to have solved this problem, but to extend my
> understanding
> of how Mathematica does things, I worked out a different solution:
>
> solveElement[eqn_, k_] := (
>       sum1 = ReplacePart[eqn, k - 1, {1, 2, 3} ][[1]];
>       sum2 = ReplacePart[eqn, k + 1, {1, 2, 2} ][[1]];
>       Rule[Part[ReplacePart[eqn, k, {1, 1, 1} ], 1, 2],
>         Part[eqn, 2] - (sum1 + sum2) ]  );
>
> This function *assumes* that eqn is of the form Sum[symbol[i], iterator]==
> r.h.s, and k is the index of the term to be solved for (it can be symbolic
> or numeric ).
>     It breaks the equation expression down by parts, replaces the parts as
> needed, and returns the rule.  All it does is manipulate the eqn
> expression
> passed to it and returns the manipulated expression -- no other
> assumptions
> about eqn are necessary, as far as i know so far.  Doing it this
> way doesn't
> require any Hold[], but it is a little rigid about the form of eqn.
>     Some results: (outputs are printed in input form)
>
> Symbolic sum, symbolic index:
> In[409]:=
> solveElement[eqn, k]
>
> Out[409]=
> a[k] -> x - Sum[a[i], {i, 1, k - 1}] - Sum[a[i], {i, k + 1, N}]
>
>
> Symbolic sum, numeric index:
> In[410]:=
> solveElement[eqn, 5]
>
> Out[410]=
> a[5] -> x - a[1] - a[2] - a[3] - a[4] - Sum[a[i], {i, 6, N}]
>
> One awkwardness is that you have to be clever about applying further rules
> in order to solve a sum with defined terms:
> In[427]:=
> eqn2 = Sum[a[i] , {i, 1, N} ] == 25.
> Out[427]=
> Sum[a[i], {i, 1, N}] == 25.
>
>
> In[447]:=
> solveElement[eqn2, 4] /. {N -> 6, a[4] -> x, a[i_] -> E^-i}
> Out[447]=
> x -> 24.4378
>
> I'm sure there are simpler ways to do take this approach as well -- like
> just passing solveElement the r.h.s. of the equation, and setting
> Sum[a[i],{i,initial,final} ] to it inside the function.
> -mark harder
>
>
> -----Original Message-----
> From: David Park <djmp at earthlink.net>
To: mathgroup at smc.vnet.net
> To: mathgroup at smc.vnet.net
> Subject: [mg27275] [mg27292] [mg27270] RE: [mg27260] Solving for Sum element
>
>
> >Ben,
> >
> >Here is one approach:
> >
> >Attributes[SumTermSolve] = {HoldFirst};
> >SumTermSolve[sumequation_, index_] :=
> >  Module[{seqn = Hold[sumequation], i, t, start, end},
> >   seqn = ReleaseHold[seqn /. Sum -> sum];
> >    seqn = seqn /. sum[t_, {i_, start_, end_}] ->
> >       sum[t, {i, start, index - 1}] + term[index] +
> >        sum[t, {i, index + 1, end}];
> >    Solve[seqn, term[index]] /. sum -> Sum]
> >
> >f[i_] := i
> >
> >SumTermSolve[Sum[f[i], {i, 1, n}] == 0, 3]
> >{{term[3] -> -3 - 1/2*(-3 + n)*(4 + n)}}
> >
> >SumTermSolve[Sum[a[i], {i, 0, 6}] == x, 2]
> >{{term[2] -> x - a[0] - a[1] - a[3] - a[4] - a[5] -
> >     a[6]}}
> >
> >
> >David Park
> >djmp at earthlink.net
> >http://home.earthlink.net/~djmp/
> >
> >
> >
> >> From: Ben Jacobson [mailto:bjacobson at illumitech.com]
To: mathgroup at smc.vnet.net
> To: mathgroup at smc.vnet.net
> >To: mathgroup at smc.vnet.net
> >>
> >> I want to solve for one element in an equation involving long
> sums.  The
> >> actual equation is of course complicated, but a very simplified example
> >> would be
> >>
> >> Sum[a[i],{i,0,n}]==x
> >>
> >> where I want to solve for a[0].  The solution should be something like
> >> a[0]->x-Sum[a[i],{i,1,n}.
> >>
> >> Solve[Sum[a[i], {i, 0, n}] == x, a[0]]
> >>
> >> works fine if, for example, n=3, but it returns an empty result for
> >> symbolic n.  Is there a way to tell Solve to assume that n>1
> and to solve
> >> accordingly?  The best I've been able to do so far is to explicitly
> remove
> >> the element I'm interested in from the sum:
> >>
> >> In: Solve[a[0] + Sum[a[i], {i, 1, n}] == x, a[0]]
> >> Out: {{a[0] -> x - Sum[a[i], {i, 1, n}]}}
> >>
> >> This works nicely, but becomes awkward when I try to solve for more
> >> elements and longer sums.  Thanks.
> >>
> >> Ben Jacobson
> >> Illumitech Inc.
> >>
> >
> >
>
>
>



  • Prev by Date: Re: RE: Solving for Sum element
  • Next by Date: simple Problem: D[ ]
  • Previous by thread: Re: RE: Solving for Sum element
  • Next by thread: two y-axis