<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Puzzler: Working with polynomials</title>
	<atom:link href="http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/</link>
	<description>Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.</description>
	<lastBuildDate>Wed, 15 Feb 2012 15:22:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1182</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 02 Sep 2008 14:36:09 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1182</guid>
		<description>Wow!

I have been out for a week, so I have not been able to respond to all the great comments here.  I find it interesting how the challenge evolved.

First many people solve the problem and then people start to see edge cases where the square term is zero.  Then people find that the test for this edge case can be found more effectively in a different way.

This kind of hardening of the code is exactly why we have frequent &quot;code reviews&quot; at The MathWorks to make sure many eyes see code before it enters the testing stage and finally the product itself.

Thanks everyone!
Doug</description>
		<content:encoded><![CDATA[<p>Wow!</p>
<p>I have been out for a week, so I have not been able to respond to all the great comments here.  I find it interesting how the challenge evolved.</p>
<p>First many people solve the problem and then people start to see edge cases where the square term is zero.  Then people find that the test for this edge case can be found more effectively in a different way.</p>
<p>This kind of hardening of the code is exactly why we have frequent &#8220;code reviews&#8221; at The MathWorks to make sure many eyes see code before it enters the testing stage and finally the product itself.</p>
<p>Thanks everyone!<br />
Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1192</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Sat, 30 Aug 2008 14:44:09 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1192</guid>
		<description>This is my solution:

&lt;pre&gt; &lt;code&gt;

coef1 = rand(1,3)-0.5;
coef2 = rand(1,3)-0.5;

der1 = polyder(coef1);
ex1 = roots(der1);

x = linspace(ex1-3,ex1+3);

curve1 = polyval(coef1,x);
curve2 = polyval(coef2,x);

marker1 = polyval(coef1,ex1);
marker2 = polyval(coef2,ex1);

plot(x,curve1,x,curve2,ex1,marker1,&#039;ks&#039;,ex1,marker2,&#039;k^&#039;)

&lt;/code&gt; &lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>This is my solution:</p>
<pre> <code>

coef1 = rand(1,3)-0.5;
coef2 = rand(1,3)-0.5;

der1 = polyder(coef1);
ex1 = roots(der1);

x = linspace(ex1-3,ex1+3);

curve1 = polyval(coef1,x);
curve2 = polyval(coef2,x);

marker1 = polyval(coef1,ex1);
marker2 = polyval(coef2,ex1);

plot(x,curve1,x,curve2,ex1,marker1,'ks',ex1,marker2,'k^')

</code> </pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tareq</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1191</link>
		<dc:creator>Tareq</dc:creator>
		<pubDate>Thu, 28 Aug 2008 13:06:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1191</guid>
		<description>coef1 = rand(1,3)-0.5;
coef2 = rand(1,3)-0.5;


lex1=roots(polyder(coef1))
lex2=roots(polyder(coef2))


hold all
plot(lex1-3:0.1:lex1+3,polyval(coef1,lex1-3:0.1:lex1+3),&#039;-&#039;);
plot(lex1-3:0.1:lex1+3,polyval(coef2,lex1-3:0.1:lex1+3),&#039;-&#039;);

plot(lex1,polyval(coef1,lex1),&#039;o&#039;);
plot(lex1,polyval(coef2,lex1),&#039;d&#039;);

xlim([lex1-3 lex1+3])</description>
		<content:encoded><![CDATA[<p>coef1 = rand(1,3)-0.5;<br />
coef2 = rand(1,3)-0.5;</p>
<p>lex1=roots(polyder(coef1))<br />
lex2=roots(polyder(coef2))</p>
<p>hold all<br />
plot(lex1-3:0.1:lex1+3,polyval(coef1,lex1-3:0.1:lex1+3),&#8217;-');<br />
plot(lex1-3:0.1:lex1+3,polyval(coef2,lex1-3:0.1:lex1+3),&#8217;-');</p>
<p>plot(lex1,polyval(coef1,lex1),&#8217;o');<br />
plot(lex1,polyval(coef2,lex1),&#8217;d');</p>
<p>xlim([lex1-3 lex1+3])</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luca Balbi</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1190</link>
		<dc:creator>Luca Balbi</dc:creator>
		<pubDate>Thu, 28 Aug 2008 12:41:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1190</guid>
		<description>While we&#039;re at it...
Checking for a number to be zero is tricky in itself.

We&#039;re better off using
&lt;pre&gt;&lt;code&gt;
if (abs(coef1(1)) &lt; eps)
   error(&#039;Error: Generated polynomial is not quadratic!&#039;);
end
&lt;/code&gt;&lt;/pre&gt;

revised code:

&lt;pre&gt;&lt;code&gt;
coef1 = rand(1,3)-0.5;
coef2 = rand(1,3)-0.5;

if (abs(coef1(1)) &lt; eps)
   error(&#039;Error: Generated polynomial is not quadratic!&#039;);
end

extremum = (-coef1(2)/(2*coef1(1)));

x = linspace(extremum-3,extremum+3);

Y =  [coef1 ; coef2] * [x.^2 ; x ; ones(1,length(x))];
yi = [coef1 ; coef2] * [extremum.^2 ; extremum ; 1];

figure
plot(x,Y(1,:),&#039;r&#039;)
hold on
plot(x,Y(2,:),&#039;k&#039;)
plot(extremum,yi(1),&#039;ks&#039;)
plot(extremum,yi(2),&#039;r^&#039;)
&lt;/code&gt;&lt;/pre&gt;

by the way, infinity is the correct answer in the limit of the 2nd degree coefficient going to zero, as long as the first degree coefficient is not zero: in that case infinity is not the solution either.</description>
		<content:encoded><![CDATA[<p>While we&#8217;re at it&#8230;<br />
Checking for a number to be zero is tricky in itself.</p>
<p>We&#8217;re better off using</p>
<pre><code>
if (abs(coef1(1)) &lt; eps)
   error('Error: Generated polynomial is not quadratic!');
end
</code></pre>
<p>revised code:</p>
<pre><code>
coef1 = rand(1,3)-0.5;
coef2 = rand(1,3)-0.5;

if (abs(coef1(1)) &lt; eps)
   error('Error: Generated polynomial is not quadratic!');
end

extremum = (-coef1(2)/(2*coef1(1)));

x = linspace(extremum-3,extremum+3);

Y =  [coef1 ; coef2] * [x.^2 ; x ; ones(1,length(x))];
yi = [coef1 ; coef2] * [extremum.^2 ; extremum ; 1];

figure
plot(x,Y(1,:),'r')
hold on
plot(x,Y(2,:),'k')
plot(extremum,yi(1),'ks')
plot(extremum,yi(2),'r^')
</code></pre>
<p>by the way, infinity is the correct answer in the limit of the 2nd degree coefficient going to zero, as long as the first degree coefficient is not zero: in that case infinity is not the solution either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1189</link>
		<dc:creator>david</dc:creator>
		<pubDate>Thu, 28 Aug 2008 08:19:06 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1189</guid>
		<description>perhaps some error checking is in order. After all, it is possible that our randomly generated quadratic happens to be linear ( coef1(1) == 0 ). In this case, the first three codes above codes throw a cryptic error &quot;Inner matrix dimensions must agree.&quot; from which it is not obvious what has gone wrong (roots(polyder) returns an empty matrix). The last code runs without error, but produces nothing as extremum has value +/-Inf

Since this error is fairly unlikely, simply running the code a bunch of times with random input probably won&#039;t notice it. What caught my attention was the last code, which happily sticks a random number from an interval containing zero at the bottom of a fraction.

A quick check to make we have a quadratic before diving in to extreme point finding may be in order:
&lt;pre&gt; &lt;code&gt;
if (coef1(1) == 0)
   error(&#039;Error: Generated polynomial is not quadratic!&#039;);
end
&lt;/code&gt; &lt;/pre&gt;
Regards,
David</description>
		<content:encoded><![CDATA[<p>perhaps some error checking is in order. After all, it is possible that our randomly generated quadratic happens to be linear ( coef1(1) == 0 ). In this case, the first three codes above codes throw a cryptic error &#8220;Inner matrix dimensions must agree.&#8221; from which it is not obvious what has gone wrong (roots(polyder) returns an empty matrix). The last code runs without error, but produces nothing as extremum has value +/-Inf</p>
<p>Since this error is fairly unlikely, simply running the code a bunch of times with random input probably won&#8217;t notice it. What caught my attention was the last code, which happily sticks a random number from an interval containing zero at the bottom of a fraction.</p>
<p>A quick check to make we have a quadratic before diving in to extreme point finding may be in order:</p>
<pre> <code>
if (coef1(1) == 0)
   error('Error: Generated polynomial is not quadratic!');
end
</code> </pre>
<p>Regards,<br />
David</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luca Balbi</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1188</link>
		<dc:creator>Luca Balbi</dc:creator>
		<pubDate>Thu, 28 Aug 2008 07:31:20 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1188</guid>
		<description>A 2nr order polynomial is just the old parabola from high school. It extremum is called the vertex and has analytically known coordinates. Its x coordinate is just
&lt;pre&gt;&lt;code&gt;
(-coef1(2)/(2*coef1(1)))
&lt;/code&gt;&lt;/pre&gt;

My solution is the following:
&lt;pre&gt;&lt;code&gt;
coef1 = rand(1,3)-0.5;
coef2 = rand(1,3)-0.5;

extremum = (-coef1(2)/(2*coef1(1)));

x = linspace(extremum-3,extremum+3);

Y =  [coef1 ; coef2] * [x.^2 ; x ; ones(1,length(x))];
yi = [coef1 ; coef2] * [extremum.^2 ; extremum ; 1];

figure
plot(x,Y(1,:),&#039;r&#039;)
hold on
plot(x,Y(2,:),&#039;k&#039;)
plot(extremum,yi(1),&#039;ks&#039;)
plot(extremum,yi(2),&#039;r^&#039;)
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>A 2nr order polynomial is just the old parabola from high school. It extremum is called the vertex and has analytically known coordinates. Its x coordinate is just</p>
<pre><code>
(-coef1(2)/(2*coef1(1)))
</code></pre>
<p>My solution is the following:</p>
<pre><code>
coef1 = rand(1,3)-0.5;
coef2 = rand(1,3)-0.5;

extremum = (-coef1(2)/(2*coef1(1)));

x = linspace(extremum-3,extremum+3);

Y =  [coef1 ; coef2] * [x.^2 ; x ; ones(1,length(x))];
yi = [coef1 ; coef2] * [extremum.^2 ; extremum ; 1];

figure
plot(x,Y(1,:),'r')
hold on
plot(x,Y(2,:),'k')
plot(extremum,yi(1),'ks')
plot(extremum,yi(2),'r^')
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Briggs</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1187</link>
		<dc:creator>Mike Briggs</dc:creator>
		<pubDate>Wed, 27 Aug 2008 17:15:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1187</guid>
		<description>OK, here is my totally AR* comment: extrema is plural; for a quadratic, there can be only one local extremum (the singular version of extrema).

Yours in good grammar, Mike Briggs (-:

* AR: anal-retentive</description>
		<content:encoded><![CDATA[<p>OK, here is my totally AR* comment: extrema is plural; for a quadratic, there can be only one local extremum (the singular version of extrema).</p>
<p>Yours in good grammar, Mike Briggs (-:</p>
<p>* AR: anal-retentive</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danilo</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1186</link>
		<dc:creator>Danilo</dc:creator>
		<pubDate>Tue, 26 Aug 2008 20:07:12 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1186</guid>
		<description>&lt;pre&gt;&lt;code&gt;coef1 = rand(1,3)-0.5;
coef2 = rand(1,3)-0.5;

infl = roots(polyder(coef1));

xx = linspace(infl-3, infl+3);
xx(50) = infl;
y1 = polyval(coef1, xx);
y2 = polyval(coef2, xx);

plot(xx, y1, &#039;r&#039;, xx, y2, &#039;k&#039;,...
    infl, y1(50), &#039;sk&#039;, infl, y2(50), &#039;^k&#039;);&lt;/pre&gt;&lt;/code&gt;</description>
		<content:encoded><![CDATA[<pre><code>coef1 = rand(1,3)-0.5;
coef2 = rand(1,3)-0.5;

infl = roots(polyder(coef1));

xx = linspace(infl-3, infl+3);
xx(50) = infl;
y1 = polyval(coef1, xx);
y2 = polyval(coef2, xx);

plot(xx, y1, 'r', xx, y2, 'k',...
    infl, y1(50), 'sk', infl, y2(50), '^k');</code></pre>
<p></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J.Paul R</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1185</link>
		<dc:creator>J.Paul R</dc:creator>
		<pubDate>Tue, 26 Aug 2008 16:23:53 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1185</guid>
		<description>BTW, here&#039;s my code for inflection points.  I don&#039;t think there are any edge cases to worry about with 3rd order polynomials. (Like x=0 for x^4)

&lt;pre&gt; &lt;code&gt;
coef1 = rand(1,4)-0.5;
coef2 = rand(1,4)-0.5;

der2 = polyder(polyder(coef1));
infpt = roots(der2);

x = linspace(infpt-3,infpt+3);

Y1 = polyval(coef1,x);
Y2 = polyval(coef2,x);
yi1 = polyval(coef1,infpt);
yi2 = polyval(coef2,infpt);

figure(1)
clf
plot(x,Y1,&#039;r&#039;)
hold on
plot(x,Y2,&#039;k&#039;)
plot(infpt,yi1,&#039;ks&#039;)
plot(infpt,yi2,&#039;k^&#039;)


&lt;/code&gt; &lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>BTW, here&#8217;s my code for inflection points.  I don&#8217;t think there are any edge cases to worry about with 3rd order polynomials. (Like x=0 for x^4)</p>
<pre> <code>
coef1 = rand(1,4)-0.5;
coef2 = rand(1,4)-0.5;

der2 = polyder(polyder(coef1));
infpt = roots(der2);

x = linspace(infpt-3,infpt+3);

Y1 = polyval(coef1,x);
Y2 = polyval(coef2,x);
yi1 = polyval(coef1,infpt);
yi2 = polyval(coef2,infpt);

figure(1)
clf
plot(x,Y1,'r')
hold on
plot(x,Y2,'k')
plot(infpt,yi1,'ks')
plot(infpt,yi2,'k^')

</code> </pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: J.Paul R</title>
		<link>http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1184</link>
		<dc:creator>J.Paul R</dc:creator>
		<pubDate>Tue, 26 Aug 2008 16:16:08 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/08/26/puzzler-working-with-polynomials/#comment-1184</guid>
		<description>The real puzzler is: &quot;what is this puzzler?&quot;  Your text ask for an &quot;inflection point&quot; while your example shows an extrema.  Additional, 3 coefficients specify a 2nd degree polynomial which has no inflection points.  So are you looking for extrema or inflection points? Or perhaps the extrema of the first derivative, which is, generally, an inflection point of the original polynomial?</description>
		<content:encoded><![CDATA[<p>The real puzzler is: &#8220;what is this puzzler?&#8221;  Your text ask for an &#8220;inflection point&#8221; while your example shows an extrema.  Additional, 3 coefficients specify a 2nd degree polynomial which has no inflection points.  So are you looking for extrema or inflection points? Or perhaps the extrema of the first derivative, which is, generally, an inflection point of the original polynomial?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

