On 3/8/2011 11:30 PM, Roger Stafford wrote:
> "Azrul " <azrul.afifi@gmail.com> wrote in message
> <il6hmu$5gd$1@fred.mathworks.com>...
>> I have a coding that store positive and negative value in a loop.
>> However, seems that only positive values are stored while there are
>> Matlab shows 'NaN' for negative values. My code is :
>> .......
>        
> It looks as though your iteration is an attempt to converge on one of
> the roots of x^35*x^23*x+25 = 0, namely the root x = 2.7165. The three
> roots of this cubic are necessarily fixed points in that iteration.
>
> Unfortunately in the near vicinity of the above root your iteration is
> highly unstable and diverges from, rather than converges to, the root.
> If an x value is a tiny epsilon above the root, the next x will be about
> 1.675*epsilon below the root and successive iterations will oscillate
> endlessly above and below the root, never remaining near the root for
> very long. In my trial run the largest x, excluding the initial 4 was
> 3.9152 and the smallest was 2.1605 (in agreement with dpb's findings,)
> and approaches to these two extremes were still being made near the end
> of the thousand iterations. If you make a plot of the successive x
> values, you will see what I mean.
I was rushed for time last night so to amplify...
If, indeed the goal is to find the roots, Matlab has much better
tools...if one is only interested in a real root, fzero is much more
robust than the above scheme...
>> fzero(inline('x^3  5*x^2 + 25'),4)
ans =
1.9030
>>
Succeeds even w/ a pretty sorry initial starting point...
If one desires all the roots, then roots() is the choice...
>> roots([1,5,0,25])
ans =
3.4515 + 1.1063i
3.4515  1.1063i
1.9030
>>

