Why just not writing Horner's algorithm directly ?
functionout=horner_mat(p,
X)a=coeff(p)out=zeros(X);fork=degree(p):-1:0out=out*X+a(k+1)*eye()endendfunction-->
a=[1 2;3 4]a = 1. 2.3. 4.--> horner_mat(1+%s-%s^2,a)ans =-5. -8. -12.
-17.--> eye() + a - a^2ans =-5. -8. -12. -17.S.
Le 24/09/2019 à 10:31, Dang Ngoc Chan, Christophe a écrit :
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
users@lists.scilab.org
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
--
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
http://www.utc.fr/~mottelet
_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users