Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: Difference /recurrence equations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35135] Re: [mg35127] Difference /recurrence equations
  • From: Murray Eisenberg <murraye at attbi.com>
  • Date: Tue, 25 Jun 2002 19:55:15 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200206250742.DAA00020@smc.vnet.net>
  • Reply-to: murray at math.umass.edu
  • Sender: owner-wri-mathgroup at wolfram.com

The recurrence relation you give evidently has at least one
typographical error: presumably it's y throughout or else Y; and did you
really want the third term on the left to be the constant 3Y(1), or
perhaps 3Y(t)?  Assuming the latter, here's how to do it in Mathematica:

  <<DiscreteMath`RSolve`                   (* load the needed Standard
AddOn package *)

  RSolve[y[t + 2] - 2 y[t + 1] + 3 y[t] == 4, y[t], t]     (* no initial
condition *)

{{y[t] -> (-4*(-2 + (1 - I*Sqrt[2])^t + (1 + I*Sqrt[2])^
        t) + I*Sqrt[2]*((1 - I*Sqrt[2])^t - 
       (1 + I*Sqrt[2])^t)*C[1] + 
     ((1 - I*Sqrt[2])^t*(2 - I*Sqrt[2]) + 

  RSolve[{y[t + 2] - 2 y[t + 1] + 3 y[t] == 4, y[0] == 5, y[1] == -3},
y[t], t]    (* with a set of initial conditions *)

  {{y[t] -> (4 + (1 - I*Sqrt[2])^t*(3 - (4*I)*Sqrt[2]) + (1 +
I*Sqrt[2])^t*(3 + (4*I)*Sqrt[2]))/2}}

In each case I'm showing the output not as you would normally see it in
Mathematica -- built up in a two-dimensional layout -- but converted to
a strictly linear InputForm for inclusion in ASCII e-mail.

In each case, also, the output is in the form of a list of a list whose
sole member is a replacement rule for the solution.  Typically, you
would want to assign the rule some name so as to be able to use it in
further computations.  In the case of the recurrence together with
initial conditions, for example, I would normally do it like this:

   soln = First @ RSolve[{y[t + 2] - 2 y[t + 1] + 3 y[t] == 4, y[0] ==
5, y[1] == -3}, y[t], t]
{y[t] -> (4 + (1 - I*Sqrt[2])^t*(3 - (4*I)*Sqrt[2]) + (1 +
I*Sqrt[2])^t*(3 + (4*I)*Sqrt[2]))/2}

(The use of First is to get rid of the outermost of the doubly-nested
list.)

Then to find y[10], say, you could evaluate as follows:

  y[t] /. soln /. t -> 10
(4 + (1 - I*Sqrt[2])^10*(3 - (4*I)*Sqrt[2]) + (1 + I*Sqrt[2])^10*(3 +
(4*I)*Sqrt[2]))/2

  Simplify[%]    (* or, here, Expand would accomplish the same thing *)
-545

If you are, in fact, going to do further computations with the solution
y[t], then it may be advantageous to get the solution not as a
replacement rule for the expression y[t], but instead as a replacement
rule for the function y itself.  In this case, the second argument to
RSolve should be y instead of y[t], and the result will express y as a
"pure function":

  soln = First @ RSolve[{y[t + 2] - 2 y[t + 1] + 3 y[t] == 4, y[0] == 5,
y[1] == -3}, y, t]
{y -> ((4 + (1 - I*Sqrt[2])^#1*(3 - (4*I)*Sqrt[2]) + (1 +
I*Sqrt[2])^#1*(3 + (4*I)*Sqrt[2]))/2 & )}

Then to find y[10], say, it's a little simpler:

  y[10] /. soln
(4 + (1 - I*Sqrt[2])^10*(3 - (4*I)*Sqrt[2]) + (1 + I*Sqrt[2])^10*(3 +
(4*I)*Sqrt[2]))/2
  
  Simplify[%]
-545

And then you can more readily do calculations such as:

  y[t] + y[t + 1] /. soln


(I hope this helps.  But I think you need to read a short introduction
to Mathematica.)


Andrew Biggs wrote:
> 
> I'm new to Mathematica and am having trouble with inputting the
> equations I'm looking to solve. I know the basic input of RSolve, but
> can't quite get it. Here's a sample problem, if anyone could show me
> how to input into RSolve I can probably run with the ball after that.
> 
> y(t+2) - 2Y(t+1) + 3Y(1) = 4
> 
> With the part in brackets being a subscript denoting time. I know it
> sounds dumb, but I just don't know the input notatin well enough to
> get a problem typed in correctly, and the Mathematica book is a little
> overwhelming.
> 
> Any help greatly appreciated!
> 
> Andrew

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.       
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street
Amherst, MA 01375


  • Prev by Date: Pretty output
  • Next by Date: RE: Simple question on whether function is defined or not
  • Previous by thread: Difference /recurrence equations
  • Next by thread: Re: Difference /recurrence equations