<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324</link>
    <title>MATLAB Central Newsreader - Matlab Problem!!!</title>
    <description>Feed for thread: Matlab Problem!!!</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 03 Dec 2008 04:23:30 -0500</pubDate>
      <title>Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614653</link>
      <author>Matt</author>
      <description>I'm trying to run the program:&lt;br&gt;
&lt;br&gt;
function [x,numIts]=newton(f,x)&lt;br&gt;
EPSILON = 1.0e-6;&lt;br&gt;
MAXITS  = 500;&lt;br&gt;
&lt;br&gt;
for numIts=1:MAXITS&lt;br&gt;
&amp;nbsp;&amp;nbsp;[y,yprime] = feval(f,x);&lt;br&gt;
&amp;nbsp;&amp;nbsp;increment = y\yprime;&lt;br&gt;
&amp;nbsp;&amp;nbsp;x = x - increment;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;if norm(increment)&amp;lt;EPSILON&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
But cannot seem to get it to run.  What commands do I need&lt;br&gt;
to enter to get this thing to run?!?!?!  Thank you for the&lt;br&gt;
help</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 04:44:16 -0500</pubDate>
      <title>Re: Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614655</link>
      <author>Walter Roberson</author>
      <description>Matt wrote:&lt;br&gt;
&amp;gt; I'm trying to run the program:&lt;br&gt;
&lt;br&gt;
&amp;gt; function [x,numIts]=newton(f,x)&lt;br&gt;
[etc]&lt;br&gt;
&lt;br&gt;
&amp;gt; But cannot seem to get it to run.  What commands do I need&lt;br&gt;
&amp;gt; to enter to get this thing to run?!?!?!&lt;br&gt;
&lt;br&gt;
What, more precisely, have you tried so far?&lt;br&gt;
&lt;br&gt;
Are you familiar with construction .m files? Are you familiar with&lt;br&gt;
how to call functions in matlab? What parameters are you passing in&lt;br&gt;
when you call it?&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
.signature note: I am now avoiding replying to unclear or ambiguous postings.&lt;br&gt;
Please review questions before posting them. Be specific. Use examples of what you mean,&lt;br&gt;
of what you don't mean. Specify boundary conditions, and data classes and value&lt;br&gt;
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 05:08:30 -0500</pubDate>
      <title>Re: Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614658</link>
      <author>Matt</author>
      <description>I've tried many things.  I already have it saved as newton.m file.  And I'm trying multiple things in the M-File Configuration Box.  I've tried:&lt;br&gt;
&lt;br&gt;
x = 1;&lt;br&gt;
f = [@(x)x.^2, @(x)2*x];&lt;br&gt;
newton(f, 0.2);&lt;br&gt;
&lt;br&gt;
f = 'x^2';&lt;br&gt;
newton(f, 0.2);&lt;br&gt;
&lt;br&gt;
newton('x^2', 0.2);&lt;br&gt;
&lt;br&gt;
And all of them give crazy errors :(</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 06:40:19 -0500</pubDate>
      <title>Re: Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614664</link>
      <author>Roger Stafford</author>
      <description>Matt &amp;lt;mcushi2@gmail.com&amp;gt; wrote in message &amp;lt;6200318.1228278241565.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I'm trying to run the program:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; function [x,numIts]=newton(f,x)&lt;br&gt;
&amp;gt; EPSILON = 1.0e-6;&lt;br&gt;
&amp;gt; MAXITS  = 500;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for numIts=1:MAXITS&lt;br&gt;
&amp;gt;   [y,yprime] = feval(f,x);&lt;br&gt;
&amp;gt;   increment = y\yprime;&lt;br&gt;
&amp;gt;   x = x - increment;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   if norm(increment)&amp;lt;EPSILON&lt;br&gt;
&amp;gt;     break;&lt;br&gt;
&amp;gt;   end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But cannot seem to get it to run.  What commands do I need&lt;br&gt;
&amp;gt; to enter to get this thing to run?!?!?!  Thank you for the&lt;br&gt;
&amp;gt; help&lt;br&gt;
&lt;br&gt;
Matt &amp;lt;mcushi2@gmail.com&amp;gt; wrote in message &amp;lt;23500797.1228280941124.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I've tried many things.  I already have it saved as newton.m file.  And I'm trying multiple things in the M-File Configuration Box.  I've tried:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x = 1;&lt;br&gt;
&amp;gt; f = [@(x)x.^2, @(x)2*x];&lt;br&gt;
&amp;gt; newton(f, 0.2);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; f = 'x^2';&lt;br&gt;
&amp;gt; newton(f, 0.2);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; newton('x^2', 0.2);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And all of them give crazy errors :(&lt;br&gt;
----------&lt;br&gt;
&amp;nbsp;&amp;nbsp;The &quot;increment = y\yprime&quot; line is wrong.  It should be a forward slash.  As it stands, you are dividing the derivative by the function value instead of visa versa.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Also, if x is intended to be a scalar quantity, and therefore 'increment' also a scalar, why do you say &quot;norm(increment)&quot; instead of just plain &quot;abs(increment)&quot;?  It will still give the correct answer but is misleading to anyone who reads the code.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;As to the three attempts to call 'newton' in your second article, the second two tries are bound to fail since they don't return the desired derivative.  'feval' is certainly not smart enough to furnish a derivative of its own accord.  Also what was the point in writing &quot;x = 1;&quot; there?&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 07:33:05 -0500</pubDate>
      <title>Re: Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614668</link>
      <author>Bruno Luong</author>
      <description>Matt &amp;lt;mcushi2@gmail.com&amp;gt; wrote in message &amp;lt;23500797.1228280941124.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And all of them give crazy errors :(&lt;br&gt;
&lt;br&gt;
You gain a lot by learning how to use the debugger to trackdown what could be wrong in the code.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 07:41:04 -0500</pubDate>
      <title>Re: Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614669</link>
      <author>Rodney Thomson</author>
      <description>Matt &amp;lt;mcushi2@gmail.com&amp;gt; wrote in message &amp;lt;6200318.1228278241565.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I'm trying to run the program:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; function [x,numIts]=newton(f,x)&lt;br&gt;
&amp;gt; EPSILON = 1.0e-6;&lt;br&gt;
&amp;gt; MAXITS  = 500;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for numIts=1:MAXITS&lt;br&gt;
&amp;gt;   [y,yprime] = feval(f,x);&lt;br&gt;
&amp;gt;   increment = y\yprime;&lt;br&gt;
&amp;gt;   x = x - increment;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   if norm(increment)&amp;lt;EPSILON&lt;br&gt;
&amp;gt;     break;&lt;br&gt;
&amp;gt;   end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But cannot seem to get it to run.  What commands do I need&lt;br&gt;
&amp;gt; to enter to get this thing to run?!?!?!  Thank you for the&lt;br&gt;
&amp;gt; help&lt;br&gt;
&lt;br&gt;
Look up the help for feval as it DOES NOT DO WHAT YOU ARE TRYING IT TO DO!&lt;br&gt;
&lt;br&gt;
It executes a MATLAB function, not a generic mathematic function. You need to wrap your mathematical function in a MATLAB function first:&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; eqtn = @(x)(x^2)&lt;br&gt;
eqtn = &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@(x)(x^2)&lt;br&gt;
&amp;gt;&amp;gt; feval(eqtn, 4)&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;16&lt;br&gt;
&lt;br&gt;
Rod&lt;br&gt;
&lt;br&gt;
--&lt;br&gt;
&lt;a href=&quot;http://iheartmatlab.blogspot.com&quot;&gt;http://iheartmatlab.blogspot.com&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 08:51:03 -0500</pubDate>
      <title>Re: Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614679</link>
      <author>Bjorn Gustavsson</author>
      <description>Matt &amp;lt;mcushi2@gmail.com&amp;gt; wrote in message &amp;lt;23500797.1228280941124.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I've tried many things.  I already have it saved as newton.m file.  And I'm trying multiple things in the M-File Configuration Box.  I've tried:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x = 1;&lt;br&gt;
&amp;gt; f = [@(x)x.^2, @(x)2*x];&lt;br&gt;
&amp;gt; newton(f, 0.2);&lt;br&gt;
&amp;gt; &lt;br&gt;
In my current version of matlab (7.1) the above pattern doesn't work, since you'd get a call along this line somewhere:&lt;br&gt;
&lt;br&gt;
val  = f(1)(12)&lt;br&gt;
&lt;br&gt;
As far as I recall the recommendation with arrays of function handles are to use cell arrays:&lt;br&gt;
&lt;br&gt;
f = {@(x) (x.^2), @(x) (2*x)};&lt;br&gt;
&lt;br&gt;
Then the call will be something like this:&lt;br&gt;
fv = f{1}(12);&lt;br&gt;
dfdx = f{2}(12);&lt;br&gt;
&lt;br&gt;
The problem is that matlab is designed with multiple usage of ().&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
Bjorn</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 14:44:57 -0500</pubDate>
      <title>Re: Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614757</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Bjorn Gustavsson&quot; &amp;lt;bjonr@irf.se&amp;gt; wrote in message &lt;br&gt;
news:gh5h9n$m1o$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Matt &amp;lt;mcushi2@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;lt;23500797.1228280941124.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; I've tried many things.  I already have it saved as newton.m file.  And &lt;br&gt;
&amp;gt;&amp;gt; I'm trying multiple things in the M-File Configuration Box.  I've tried:&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; x = 1;&lt;br&gt;
&amp;gt;&amp;gt; f = [@(x)x.^2, @(x)2*x];&lt;br&gt;
&amp;gt;&amp;gt; newton(f, 0.2);&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; In my current version of matlab (7.1) the above pattern doesn't work, &lt;br&gt;
&amp;gt; since you'd get a call along this line somewhere:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; val  = f(1)(12)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; As far as I recall the recommendation with arrays of function handles are &lt;br&gt;
&amp;gt; to use cell arrays:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; f = {@(x) (x.^2), @(x) (2*x)};&lt;br&gt;
&lt;br&gt;
It depends on what the OP wants.  Rather than a cell array of function &lt;br&gt;
handles, I suspect he may want a function handle that returns an array:&lt;br&gt;
&lt;br&gt;
f = @(x) [x.^2; 2*x];&lt;br&gt;
&lt;br&gt;
Then something like f(5) would work.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 17:14:02 -0500</pubDate>
      <title>Re: Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614816</link>
      <author>Roger Stafford</author>
      <description>&quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;gh59kj$hrr$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Matt &amp;lt;mcushi2@gmail.com&amp;gt; wrote in message &amp;lt;6200318.1228278241565.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; ......&lt;br&gt;
&amp;gt; &amp;gt; f = [@(x)x.^2, @(x)2*x];&lt;br&gt;
&amp;gt; &amp;gt; newton(f, 0.2);&lt;br&gt;
&amp;gt; &amp;gt; .......&lt;br&gt;
&amp;gt; .....&lt;br&gt;
&amp;gt;   As to the three attempts to call 'newton' in your second article, the second two tries are bound to fail since they don't return the desired derivative.  'feval' is certainly not smart enough to furnish a derivative of its own accord.&lt;br&gt;
&amp;gt; ......&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;I would also like to point out a theoretical difficulty with Newton's method that occurs with the type of function you gave as an example, Matt.  In that case the root of the equation f(x) = x^2 = 0 occurs at a point where the derivative also has a root, f'(x) = 0.  When this happens there is danger of the ratio f(x(n))/f'(x(n)) becoming indeterminate, which is to say, capable of serious computational errors in obtaining x(n+1) from x(n).&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;For example if you had used f(x) = x^2-2*pi+pi^2, with a root at x = pi, where its derivative also has a root, you would not be able to find that root to better than about eight-place accuracy using Newton's method, in spite of Matlab's general sixteen-place accuracy.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Thu, 04 Dec 2008 08:12:06 -0500</pubDate>
      <title>Re: Matlab Problem!!!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240324#614969</link>
      <author>Bjorn Gustavsson</author>
      <description>&quot;Steven Lord&quot; &amp;lt;slord@mathworks.com&amp;gt; wrote in message &amp;lt;gh6619$npo$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;Bjorn Gustavsson&quot; &amp;lt;bjonr@irf.se&amp;gt; wrote in message &lt;br&gt;
&amp;gt; news:gh5h9n$m1o$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; &amp;gt; Matt &amp;lt;mcushi2@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;gt; &amp;lt;23500797.1228280941124.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; I've tried many things.  I already have it saved as newton.m file.  And &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; I'm trying multiple things in the M-File Configuration Box.  I've tried:&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; x = 1;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; f = [@(x)x.^2, @(x)2*x];&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; newton(f, 0.2);&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; In my current version of matlab (7.1) the above pattern doesn't work, &lt;br&gt;
&amp;gt; &amp;gt; since you'd get a call along this line somewhere:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; val  = f(1)(12)&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; As far as I recall the recommendation with arrays of function handles are &lt;br&gt;
&amp;gt; &amp;gt; to use cell arrays:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; f = {@(x) (x.^2), @(x) (2*x)};&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; It depends on what the OP wants.  Rather than a cell array of function &lt;br&gt;
&amp;gt; handles, I suspect he may want a function handle that returns an array:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; f = @(x) [x.^2; 2*x];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Then something like f(5) would work.&lt;br&gt;
&amp;gt; &lt;br&gt;
Is there any neat way to make that vectorize well too - so that one get an N-by-2 array out if called with an N-by-1 and a 2-by-N when called with a 1-by-N?&lt;br&gt;
&lt;br&gt;
Bjoern, trying to learn something - sometimes</description>
    </item>
  </channel>
</rss>

