Question

Solve Recursive Equations

Asked by: Telavian

Is there a general way to get a single equation for a recursive formula?

For instance, the equation X = 2x - 1 can be written as X = (2^N)x - (2^N-1)-1 to get a single equation. Is a general way to solve possible? I solved the above based on expansion, but would like a general way to solve.

Also, for the following loop system is a general solution possible?
x = y + z
z = y + x
y = 2 * x

The items can be written as follows to get them dependant on previous iteration only:
x = y + z
y = 2y + z
z = 2y + 2z

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-11 at 10:34:01ID24643935
Tags

Math

,

Equation

,

Puzzle

Topics

Math & Science

,

Puzzles & Riddles

,

Algorithms

Participating Experts
2
Points
500
Comments
11

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. reciprocal equations
    Hello, do you know, how to solve reciprocal equations o f higher orders? I can't find anything about it. thanks
  2. Resolving equation
    Hi all if I have an equation such as, y = mx + c and if I have the value of y, m and c, can I use MS Excel to find the value of x for me? Without rearranging the equation. Thanks
  3. months equation
    Hi, I need some help with a basic date equation. I want to be able to enter a date manually, which kickstarts a column of equations that increment the date by one month (always end of month) for each row. When it reaches the end of the year (dec) it should roll over to the ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: InteractiveMindPosted on 2009-08-11 at 12:25:19ID: 25072404

First of all, I get a slightly different answer to you for your first example: X=(2^N)x - 2^(N-1).

With regards to a general solution: there are general approaches to recursive equations depending on their properties. Here's a list of solutions: http://en.wikipedia.org/wiki/Recurrence_relation#Solving

In the case of a system, let's first use the notation:

x_(n+1) = y_n + z_n
z_(n+1) = y_n + x_n
y_(n+1) = 2x_n

Then x_(n+1) = 2x_(n-1) + y_(n-1) + x_(n-1) = 4x_(n-1) + 2x_(n-2), which is equivalent to x_(n+3) = 3x_(n+1)+2x_n, which is a linear homogeneous recurrence relation (c.f. wiki)

 

by: InteractiveMindPosted on 2009-08-11 at 12:26:17ID: 25072418

(Then similarly for the y and z variables)

 

by: aburrPosted on 2009-08-11 at 15:48:49ID: 25074257

"Also, for the following loop system is a general solution possible?
x = y + z
z = y + x
y = 2 * x

Not only is no general solution possible but NO solution is possible. The equations are contradictory

 

by: TelavianPosted on 2009-08-11 at 16:16:14ID: 25074426

aburr, this is a system of recursive equations.

 

by: aburrPosted on 2009-08-11 at 19:29:47ID: 25075281

"aburr, this is a system of recursive equations."
you are right. How do you get the loop started?

 

by: TelavianPosted on 2009-08-11 at 20:52:23ID: 25075621

Each variable has some initial setting and then they loop from there:

int x = 1, y = 1, z = 1;
 
while (true) //Or some condition
{
  x = y + z;
  z = y + x;
  y = 2 * x;
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: TelavianPosted on 2009-08-11 at 20:56:52ID: 25075642

InteractiveMind, just for completness can you post the solution for x, y, and z?

Thanks.

 

by: aburrPosted on 2009-08-11 at 21:06:06ID: 25075689

I am probably still confused by the loop  but it seems to me that
the nth value of x, y, and z all = 2^n. If that is not so, do not bother to correct me as I probably do not have anything useful to contribute to this question.

 

by: InteractiveMindPosted on 2009-08-12 at 12:27:53ID: 25081960

>InteractiveMind, just for completness can you post the solution for x, y, and z?

y is found using the same method as x:

x_(n+3) - 3x_(n+1) - 2x_n = 0
y_(n+3) - 3y_(n+1) - 2y_n = 0

Finding z by rearrangement seems quite tedious though, but there's a slight trick: recall that z_(n+1)=x_n+y_n. So if we add the above two equations, we get:

[x_(n+3)+y_(n+3)] - 3[x_(n+1)+y_(n+1)] - 2[x_n+y_n] = 0

which is

z_(n+4) - 3z_(n+2) - 2z_(n+1) = 0

or

z_(n+3) - 3z_(n+1) - 2z_n = 0.

In other words, all three variables have the same solution. Which, as aburr correctly points out, has the solution x_n=y_n=z_n=2^n.


BTW, your code is not quite right.

int last_x = 1, last_y = 1, last_z = 1;
int x, y, z;
 
while (true) //Or some condition
{
  x = last_y + last_z;
  z = last_y + last_x;
  y = 2 * last_x;
  
  last_x = x;
  last_y = y;
  last_z = z;
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:

Select allOpen in new window

 

by: TelavianPosted on 2009-08-12 at 12:55:24ID: 25082224

Something is not right.
First off, my answer of X = (2^N)x - (2^N-1)-1 is correct.

My code is correct and that is what I am trying to find.
Maybe there is a misunderstanding.

The initial system is a loop and so should be "executed" top to bottom then again.
It can be rewritten as follows to get it dependent on previous: (Is this wrong?)

x_n = y_(n-1) + z_(n-1)
z_n = y_(n-1) + x_(n-1)
y_n = 2x_(n-1)

If all three are the same then running the loop would yield the same answers which it doesn't.
My goal is to remove the loop and use a single equation for x, a single for y, and so on for z.

if x = y = z = 1 then I get

1:
x: 2
y: 4
z: 3

2:
x: 7
y: 14
z: 11

3:
x: 25
y: 50
z: 39

4:
x: 89
y: 178
z: 139

5:
x: 317
y: 634
z: 495

6:
x: 1129
y: 2258
z: 1763

7:
x: 4021
y: 8042
z: 6279

8:
x: 14321
y: 28642
z: 22363

9:
x: 51005
y: 102010
z: 79647

10:
x: 181657
y: 363314
z: 283667

This is the exact code to calculate the loop.

      int x = 1;
      int y = 1;
      int z = 1;
 
      for (int c = 0; c < 10; c++)
      {
        x = y + z;
        z = y + x;
        y = 2 * x;
 
        Console.WriteLine("{0}:\r\nx: {1}\r\ny: {2}\r\nz: {3}\r\n", c+1, x, y, z);
      }
 
      Console.ReadLine();

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:

Select allOpen in new window

 

by: InteractiveMindPosted on 2009-08-13 at 06:36:46ID: 25088022

Sorry, I had misunderstood you (or rather, made incorrect assumptions). Your code is not the same as,

  x_n = y_(n-1) + z_(n-1)
  z_n = y_(n-1) + x_(n-1)
  y_n = 2x_(n-1),

instead, it is equivalent to:

  x_n = y_(n-1) + z_(n-1)
  z_n = y_(n-1) + x_n
  y_n = 2x_n,

which can be solved in a similar way (below). Let me know if you have any other questions.

===Derivation===

First, rearrange to get a recursive equation for x:

  x_(n+2) - 3x_(n+1) - 2x_n = 0

as described in the wiki article, we solve this by trying the ansatz x_n=k^n:

  k^(n+2) - 3k^(n+1) - 2k^n = 0

which gives the quadratic

  k^2 - 3k - 2 = 0

hence, k=[3 +/- sqrt(17)]/2. So the solution for x_n is:

  x_n = A*([3+sqrt(17)]/2)^n + B*([3-sqrt(17)]/2)^n,

where A and B are constants which account for our initial conditions. Before we find A and B though, you must note that for our system we require that y_n=2x_n, and so x_0=y_0=1 is not possible (unless we take n=1 to be the first element in our series, but this makes it a lot trickier to solve A and B below), so let's take x_0=2, y_0=4, z_0=3 (which is your 3-tuple for n=1). Then:

  x_0 = 2 = A + B,  and
  x_1 = y_0 + z_0 = 7 = A*([3+sqrt(17)]/2) + B*([3-sqrt(17)]/2).

Solving simultaneously for A and B we find:

  A = 1 + 8/(2*sqrt(17)),
  B = 1 - 8/(2*sqrt(17)).

Now that we know x_n, we find y_n and z_n as functions of x_n.

===Final Solution===

So putting it all together:

  x_n = {1 + 8/(2*sqrt(17))}*([3+sqrt(17)]/2)^n + {1 - 8/(2*sqrt(17))}*([3-sqrt(17)]/2)^n,
  y_n = 2*x_n, and z_n = 2*x_(n-1) + x_n,
  z_n = 2x_(n-1) + x_n.

Important: Remember that the {1+/-8/(2*sqrt(17)} terms need to be changed if you change the initial variables!

===Test===

This solution may look complicated, but it's a fairly typical solution for this type of problem, moreover, it works!

Recall that because I chose x_0 to be your x_1 (and similarly for y_0 as y_1 et cetera), we'd expect x_n from the above equation to give x_(n+1) in the numbers you computed above.

So let's take n=6 (you get x_7=4021):

  x_6 = {1 + 8/(2*sqrt(17))}*([3+sqrt(17)]/2)^6 + {1 - 8/(2*sqrt(17))}*([3-sqrt(17)]/2)^6 = 4021,

as expected. Then y_n and z_n are easily found as per above.

I've attached a Java implementation if it helps (I don't have C# installed on this computer).

class Test
{
	public static final double SQRT17 = Math.sqrt(17);
 
	public Test(int n)
	{
		System.out.println("n\tvariable\t(observed)\t(predicted)");
		
		int x = 2, y = 4, z = 3;
 
		System.out.println(0+"\tx\t\t"+x+"\t\t"+x(0));
		System.out.println("\ty\t\t"+y+"\t\t"+y(0));
		System.out.println("\tz\t\t"+z+"\t\t"+z(0));
 
		for (int c = 1; c < n; c++)
		{
			x = y + z;
			z = y + x;
			y = 2 * x;
 
			System.out.println(c+"\tx\t\t"+x+"\t\t"+x(c));
			System.out.println("\ty\t\t"+y+"\t\t"+y(c));
			System.out.println("\tz\t\t"+z+"\t\t"+z(c));
		}
 
	}
 
	public int x(int n)
	{
		return (int)((1.0 + 8.0 / (2.0 * SQRT17)) * Math.pow((3.0 + SQRT17) / 2.0, n)
				+ (1.0 - 8.0 / (2.0 * SQRT17))
				* Math.pow((3.0 - SQRT17) / 2.0, n));
	}
 
	public int y(int n)
	{
		return 2 * x(n);
	}
 
	public int z(int n)
	{
		return y(n - 1) + x(n);
	}
 
	public static void main(String[] a)
	{
		new Test(Integer.parseInt(a[0]));
	}
 
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:

Select allOpen in new window

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...