<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Actually, it was just wrong... Must not write code at 2AM... Try the following!:<div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); ">// Creates the Companion matrix for a given polynomial</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: #3f6e74">GiNaC</span>::<span style="color: #5c2699">matrix</span> CreateCompanion(<span style="color: #aa0d91">const</span> <span style="color: #3f6e74">GiNaC</span>::<span style="color: #5c2699">ex</span> &poly, <span style="color: #aa0d91">const</span> <span style="color: #3f6e74">GiNaC</span>::<span style="color: #5c2699">ex</span> &<span style="color: #2e0d6e">symbol</span>)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">{</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(46, 13, 110); "><span style="color: #000000"> </span><span style="color: #aa0d91">if</span><span style="color: #000000">(poly.</span>is_polynomial<span style="color: #000000">(</span>symbol<span style="color: #000000">))</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">int</span> rank = poly.<span style="color: #2e0d6e">degree</span>(<span style="color: #2e0d6e">symbol</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #3f6e74">GiNaC</span>::<span style="color: #5c2699">matrix</span> mat(rank, rank);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #3f6e74">GiNaC</span>::<span style="color: #5c2699">ex</span> majorCoeff = poly.<span style="color: #2e0d6e">coeff</span>(<span style="color: #2e0d6e">symbol</span>, rank);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">for</span>(<span style="color: #aa0d91">int</span> <span style="color: #3f6e74">i</span> = <span style="color: #1c00cf">0</span>; <span style="color: #3f6e74">i</span> < rank; ++<span style="color: #3f6e74">i</span>)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">for</span>(<span style="color: #aa0d91">int</span> j = <span style="color: #1c00cf">0</span>; j < rank; ++j)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">if</span>(<span style="color: #3f6e74">i</span> - j == <span style="color: #1c00cf">1</span>)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> mat(<span style="color: #3f6e74">i</span>, j) = <span style="color: #1c00cf">1</span>;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> }</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">else</span> <span style="color: #aa0d91">if</span>(j == rank - <span style="color: #1c00cf">1</span>)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> mat(<span style="color: #3f6e74">i</span>, j) = -<span style="color: #1c00cf">1</span> * poly.<span style="color: #2e0d6e">coeff</span>(<span style="color: #2e0d6e">symbol</span>, <span style="color: #3f6e74">i</span>) / majorCoeff;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> }</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> }</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> }</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">return</span> mat;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> }</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(170, 13, 145); "><span style="color: #000000"> </span>else</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span style="color: #aa0d91">return</span> <span style="color: #3f6e74">GiNaC</span>::<span style="color: #5c2699">matrix</span>();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> }</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">Regards,</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">James.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><br></div><div><div>On 18 Feb 2009, at 14:59, Jens Vollinga wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi James,<br><br>James Jackson schrieb:<br><blockquote type="cite">As far as I can see, there is no method available to compute the companion matrix of a polynomial. May I suggest the addition of a method along these lines?:<br></blockquote><br>sure, we can include such a function.<br><br>I am just a bit confused about the conventions here:<br><br><blockquote type="cite"> mat(i, j) = -1 * poly.coeff(symbol, rank - j - 1) / majorCoeff;<br></blockquote><br>Shouldn't coefficient c_j go in row j?<br><br>Regards,<br>Jens<br><br>_______________________________________________<br>GiNaC-list mailing list<br><a href="mailto:GiNaC-list@ginac.de">GiNaC-list@ginac.de</a><br>https://www.cebix.net/mailman/listinfo/ginac-list<br></div></blockquote></div><br></div></body></html>