Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Given an iterative equation to solve an equation

Subject: Given an iterative equation to solve an equation

From: Jacob

Date: 19 Jan, 2013 22:04:07

Message: 1 of 3

An iterative equation for solving the equation x^2-x-1=0 is given by
x(r+1)=1+(1/x(r)) for r=0,1,2,...
Given x0=2, write a Matlab script to solve the equation. Sufficient accuracy is obtained when abs(x(r+1)-x(r))<.0005.

I am a new to Matlab and I am having a hard time really even starting this problem. I was thinking that using some sort of loop until the accuracy condition is met would work. Any help would be much appreciated.

Thanks in advance,

Jacob

Subject: Given an iterative equation to solve an equation

From: Greg Heath

Date: 20 Jan, 2013 12:23:08

Message: 2 of 3

"Jacob" wrote in message <kdf58n$958$1@newscl01ah.mathworks.com>...
> An iterative equation for solving the equation x^2-x-1=0 is given by
> x(r+1)=1+(1/x(r)) for r=0,1,2,...
> Given x0=2, write a Matlab script to solve the equation. Sufficient accuracy is obtained when abs(x(r+1)-x(r))<.0005.
>
> I am a new to Matlab and I am having a hard time really even starting this problem. I was thinking that using some sort of loop until the accuracy condition is met would work. Any help would be much appreciated.
>
> Thanks in advance,
>
> Jacob

Your plan sounds ok to me.

Greg

Subject: Given an iterative equation to solve an equation

From: Roger Stafford

Date: 20 Jan, 2013 18:27:07

Message: 3 of 3

"Jacob" wrote in message <kdf58n$958$1@newscl01ah.mathworks.com>...
> An iterative equation for solving the equation x^2-x-1=0 is given by
> x(r+1)=1+(1/x(r)) for r=0,1,2,...
> Given x0=2, write a Matlab script to solve the equation. Sufficient accuracy is obtained when abs(x(r+1)-x(r))<.0005.
>
> I am a new to Matlab and I am having a hard time really even starting this problem. I was thinking that using some sort of loop until the accuracy condition is met would work. Any help would be much appreciated.
>
> Thanks in advance,
>
> Jacob
- - - - - - - - - -
  You will find that matlab's 'while' function is very useful for a problem like yours using the inequality you have stated. I tried it on my computer and it took nine trips through the loop before the inequality was satisfied.

  It is important to realize that in general such iterative schemes are not guaranteed to converge to a solution or may be less efficient than other iterations. It all depends on the nature of the iterative formula. In this problem for example there is a second root to the quadratic equation but this iterative scheme apparently diverges away from it rather than toward it.

  There is another iterative formula which is derived from the Newton-Raphson method that will converge much faster

 x(n+1) = (x(n)^2+1)/(2*x(n)-1)

and is capable of converging on either root depending on the initial value used.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us