Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: matlab iteration Date: Fri, 25 Mar 2011 02:16:05 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 29 Message-ID: <imgtt5$ms8$1@fred.mathworks.com> References: <imgrrg$lai$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1301019365 23432 172.30.248.48 (25 Mar 2011 02:16:05 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 25 Mar 2011 02:16:05 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:718026 "Safa" wrote in message <imgrrg$lai$1@fred.mathworks.com>... > I am trying to solve the following equation iteratively in Matlab: > y=x*(1-x)^1.39-(b) > where b is a constant. > > So for example: > a=800; > b=0.104; > x=0; > dx=0.0001; > y=-1; > while y<0 && x < 1 && a>500; > x=x+dx; > y=x*(1-x)^1.39-(b); > end > if (x > 1); > disp('x is over 1'); > end > disp(['root ' num2str(x)]) > > Code seems to work up to certain values of b. If I put however b=0.93 for example, the code stops working. Would appreciate any suggestions to improve this code. > Many thanks > Safa - - - - - - - - - - That's easy to explain. Your expression x*(1-x)^1.39 attains a maximum value of 0.19697 at x = .4184 and then begins to descend. If b is set greater than this, you will never see a positive y. You can find this out for yourself by taking the derivative of x*(1-x)^2.39 and determining when it becomes zero in order to find this maximum value and where it occurs. This should also tell you that your code is finding only one root even though for smaller b there will actually be two roots between 0 and 1. Roger Stafford