<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<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">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">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">http://www.utc.fr/~mottelet</a>
</pre>
</body>
</html>