http://www.mathworks.com/matlabcentral/newsreader/view_thread/305048
MATLAB Central Newsreader  matlab iteration
Feed for thread: matlab iteration
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 25 Mar 2011 01:41:04 +0000
matlab iteration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/305048#827263
Safa
I am trying to solve the following equation iteratively in Matlab: <br>
y=x*(1x)^1.39(b) <br>
where b is a constant. <br>
<br>
So for example:<br>
a=800;<br>
b=0.104;<br>
x=0;<br>
dx=0.0001;<br>
y=1;<br>
while y<0 && x < 1 && a>500;<br>
x=x+dx;<br>
y=x*(1x)^1.39(b);<br>
end<br>
if (x > 1);<br>
disp('x is over 1');<br>
end<br>
disp(['root ' num2str(x)])<br>
<br>
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.<br>
Many thanks<br>
Safa

Fri, 25 Mar 2011 02:16:05 +0000
Re: matlab iteration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/305048#827266
Roger Stafford
"Safa" wrote in message <imgrrg$lai$1@fred.mathworks.com>...<br>
> I am trying to solve the following equation iteratively in Matlab: <br>
> y=x*(1x)^1.39(b) <br>
> where b is a constant. <br>
> <br>
> So for example:<br>
> a=800;<br>
> b=0.104;<br>
> x=0;<br>
> dx=0.0001;<br>
> y=1;<br>
> while y<0 && x < 1 && a>500;<br>
> x=x+dx;<br>
> y=x*(1x)^1.39(b);<br>
> end<br>
> if (x > 1);<br>
> disp('x is over 1');<br>
> end<br>
> disp(['root ' num2str(x)])<br>
> <br>
> 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.<br>
> Many thanks<br>
> Safa<br>
          <br>
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.<br>
<br>
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.<br>
<br>
Roger Stafford

Fri, 25 Mar 2011 02:32:06 +0000
Re: matlab iteration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/305048#827270
Safa
"Safa" wrote in message <imgrrg$lai$1@fred.mathworks.com>...<br>
> I am trying to solve the following equation iteratively in Matlab: <br>
> y=x*(1x)^1.39(b) <br>
> where b is a constant. <br>
> <br>
> So for example:<br>
> a=800;<br>
> b=0.104;<br>
> x=0;<br>
> dx=0.0001;<br>
> y=1;<br>
> while y<0 && x < 1 && a>500;<br>
> x=x+dx;<br>
> y=x*(1x)^1.39(b);<br>
> end<br>
> if (x > 1);<br>
> disp('x is over 1');<br>
> end<br>
> disp(['root ' num2str(x)])<br>
> <br>
> 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.<br>
> Many thanks<br>
> Safa<br>
<br>
Thanks for your quick reply. I am actually trying to solve the equation x*(1x)^1.39(b)=0. Well doesn't have to be exactly zero, can be equal to 10^5 for example. So I try to vary x iteratively between 0 and 1 to find the values that would satisfy this equation. Do you suggest a better way to do this in Matlab? Again would appreciate your feedback.

Fri, 25 Mar 2011 02:32:06 +0000
Re: matlab iteration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/305048#827271
Roger Stafford
"Roger Stafford" wrote in message <imgtt5$ms8$1@fred.mathworks.com>...<br>
> 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.<br>
> ......<br>
        <br>
I made a mistake in my arithmetic. The maximum is correct but occurs at x = 0.5819 .<br>
<br>
Roger Stafford

Fri, 25 Mar 2011 02:44:04 +0000
Re: matlab iteration
http://www.mathworks.com/matlabcentral/newsreader/view_thread/305048#827272
Roger Stafford
"Safa" wrote in message <imgur5$87n$1@fred.mathworks.com>...<br>
> Thanks for your quick reply. I am actually trying to solve the equation x*(1x)^1.39(b)=0. Well doesn't have to be exactly zero, can be equal to 10^5 for example. So I try to vary x iteratively between 0 and 1 to find the values that would satisfy this equation. Do you suggest a better way to do this in Matlab? Again would appreciate your feedback. <br>
        <br>
Use matlab's 'fzero' function. By adjusting the 'x0' estimate parameter appropriately you can find both roots for b's that are below the maximum I mentioned.<br>
<br>
Roger Stafford