<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    <font face="Courier New">Stéphane,<br>
      <br>
      Thanks, this is great, the use of eye is the way to go to overcome
      the problem of an earlier suggestion which discarded, for
      instance, A + 2 for not being what Horner expects; but A +
      2*eye(A) is! <br>
      <br>
      Thanks also for making me aware of the simplified syntax 2*eye()
      which adapts its size to the matrix it is added to, and is also
      computationally more efficient, important especially for very
      large matrices.<br>
      <br>
      Best regards,<br>
      <br>
      Federico Miyara<br>
    </font><br>
    <br>
    <div class="moz-cite-prefix">On 24/09/2019 05:34, Stéphane Mottelet
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:bcddac15-ae67-ca7d-ed44-d46602aa8f8a@utc.fr">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <p><tt>Why just not writing Horner's algorithm directly ?<br>
        </tt></p>
      <pre style="font-family:Monospaced;font-style:normal;font-size:12.0;"><tt>function</tt><tt> </tt><tt>out</tt><tt>=</tt><tt><span style="text-decoration: underline;">horner_mat</span></tt><tt>(</tt><tt>p</tt><tt>, </tt><tt>X</tt><tt>)</tt><tt>
    </tt><tt>a</tt><tt> </tt><tt>=</tt><tt> </tt><tt>coeff</tt><tt>(</tt><tt>p</tt><tt>)</tt><tt>
    </tt><tt>out</tt><tt> </tt><tt>=</tt><tt> </tt><tt>zeros</tt><tt>(</tt><tt>X</tt><tt>)</tt><tt>;</tt><tt>
    </tt><tt>for</tt><tt> </tt><tt>k</tt><tt> </tt><tt>=</tt><tt> </tt><tt>degree</tt><tt>(</tt><tt>p</tt><tt>)</tt><tt>:</tt><tt>-</tt><tt>1</tt><tt>:</tt><tt>0</tt><tt>
        </tt><tt>out</tt><tt> </tt><tt>=</tt><tt> </tt><tt>out</tt><tt>*</tt><tt>X</tt><tt> </tt><tt>+</tt><tt> </tt><tt>a</tt><tt>(</tt><tt>k</tt><tt>+</tt><tt>1</tt><tt>)</tt><tt>*</tt><tt>eye</tt><tt>(</tt><tt>)</tt><tt>
    </tt><tt>end</tt><tt>
</tt><span style="color:rgb(176,24,19);"><font color="#000000"><tt>endfunction</tt><tt>
</tt><tt>
</tt><tt>--> a=[1 2;3 4]</tt><tt>
</tt><tt> a  = </tt><tt>
</tt><tt>
</tt><tt>   1.   2.</tt><tt>
</tt><tt>   3.   4.</tt><tt>
</tt><tt>
</tt><tt>
</tt><tt>--> horner_mat(1+%s-%s^2,a)</tt><tt>
</tt><tt> ans  =</tt><tt>
</tt><tt>
</tt><tt>  -5.   -8. </tt><tt>
</tt><tt>  -12.  -17.</tt><tt>
</tt><tt>
</tt><tt>
</tt><tt>--> eye() + a - a^2</tt><tt>
</tt><tt> ans  =</tt><tt>
</tt><tt>
</tt><tt>  -5.   -8. </tt><tt>
</tt><tt>  -12.  -17.</tt><tt>
</tt><tt>
</tt><tt>S.</tt></font>
</span></pre>
      <div class="moz-cite-prefix">Le 24/09/2019 à 10:31, Dang Ngoc
        Chan, Christophe a écrit :<br>
      </div>
      <blockquote type="cite"
cite="mid:DB6PR07MB434492D3F758E323E7D441F4E5840@DB6PR07MB4344.eurprd07.prod.outlook.com">
        <pre class="moz-quote-pre" wrap="">Hi,

I've got some time this morning (-: so this one seems to work and should be a bit more efficient:

// **********

P = %s^2 + 2*%s + 3

C = coeff(P)

n = size(C, "c")

if n > 1 then

    stringP = "X1 = x; "

    for i = 3:n

        stringP = stringP+"X"+string(i-1)+" = X"+string(i-2)+"*x; "

    end

else

    stringP = ""

end

stringP = stringP+"Y = "+string(C(1))

for i = 2:n

    stringP = stringP+" + "+string(C(i))+"*X"+string(i-1)

end

deff("[Y] = fctP(x)", stringP)

// **********

Regards

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer


General
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org" moz-do-not-send="true">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users" moz-do-not-send="true">https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users</a>
</pre>
      </blockquote>
      <pre class="moz-signature" cols="72">-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
<a class="moz-txt-link-freetext" href="http://www.utc.fr/~mottelet" moz-do-not-send="true">http://www.utc.fr/~mottelet</a>
</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <br>
  <div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br /> <table style="border-top: 1px solid #D3D4DE;">
        <tr>
      <td style="width: 55px; padding-top: 18px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;" /></a></td>
                <td style="width: 470px; padding-top: 17px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Libre de virus. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a>           </td>
        </tr>
</table>
<a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></body>
</html>