<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241066</link>
    <title>MATLAB Central Newsreader - How does the gradient work?</title>
    <description>Feed for thread: How does the gradient work?</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>Mon, 15 Dec 2008 15:56:14 -0500</pubDate>
      <title>How does the gradient work?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241066#617173</link>
      <author>mlt</author>
      <description>I have made this in matlab:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
x=0:9*pi/2;&lt;br&gt;
&lt;br&gt;
% Using matlab's gradient&lt;br&gt;
f = sin(x);&lt;br&gt;
FX = gradient(f);&lt;br&gt;
&lt;br&gt;
% Using the definition that df/dx for sin(x) is cos(x)&lt;br&gt;
fderv = cos(x);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
But when I print them I get:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
FX =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.8415    0.4546   -0.3502   -0.8330   -0.5500    0.2387    0.8080 &lt;br&gt;
0.6344   -0.1224   -0.7667   -0.7061    0.0037    0.7101    0.7636    0.5704&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
fderv =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.5000    0.2702   -0.2081   -0.4950   -0.3268    0.1418    0.4801 &lt;br&gt;
0.3770   -0.0728   -0.4556   -0.4195    0.0022    0.4219    0.4537    0.0684&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Why are the result different? </description>
    </item>
    <item>
      <pubDate>Mon, 15 Dec 2008 17:13:02 -0500</pubDate>
      <title>Re: How does the gradient work?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241066#617190</link>
      <author>Roger Stafford</author>
      <description>&quot;mlt&quot; &amp;lt;asdf@asd.com&amp;gt; wrote in message &amp;lt;49467e39$0$90269$14726298@news.sunsite.dk&amp;gt;...&lt;br&gt;
&amp;gt; I have made this in matlab:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x=0:9*pi/2;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Using matlab's gradient&lt;br&gt;
&amp;gt; f = sin(x);&lt;br&gt;
&amp;gt; FX = gradient(f);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Using the definition that df/dx for sin(x) is cos(x)&lt;br&gt;
&amp;gt; fderv = cos(x);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But when I print them I get:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; FX =&lt;br&gt;
&amp;gt;     0.8415    0.4546   -0.3502   -0.8330   -0.5500    0.2387    0.8080 &lt;br&gt;
&amp;gt; 0.6344   -0.1224   -0.7667   -0.7061    0.0037    0.7101    0.7636    0.5704&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; fderv =&lt;br&gt;
&amp;gt;     0.5000    0.2702   -0.2081   -0.4950   -0.3268    0.1418    0.4801 &lt;br&gt;
&amp;gt; 0.3770   -0.0728   -0.4556   -0.4195    0.0022    0.4219    0.4537    0.0684&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Why are the result different? &lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;The gradient function attempts to approximate the derivative using discretely spaced points, but your points are so far apart this approximation must necessarily be a very poor one.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;By the way, the values you give to fderv don't agree with the x you defined.  For example acos(0) is 1, not 0.5.  What is the actual x you used?&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Mon, 15 Dec 2008 17:29:03 -0500</pubDate>
      <title>Re: How does the gradient work?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241066#617193</link>
      <author>Roger Stafford</author>
      <description>&quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;gi636u$qm9$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; .....&lt;br&gt;
&amp;gt;   By the way, the values you give to fderv don't agree with the x you defined.  For example acos(0) is 1, not 0.5.  What is the actual x you used?&lt;br&gt;
&amp;gt; .....&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;I meant cos(0) is 1.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
  </channel>
</rss>

