"Safa" wrote in message <imgrrg$lai$1@fred.mathworks.com>...
> I am trying to solve the following equation iteratively in Matlab:
> y=x*(1x)^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*(1x)^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*(1x)^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*(1x)^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
