Re: [Scilab-users] Evaluating a polynomial on a square matrix

2019-09-24 Thread Federico Miyara
Stéphane, 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! Thanks also for making me aware of the simplified syntax 2*eye() which adapts its

Re: [Scilab-users] Evaluating a polynomial on a square matrix

2019-09-24 Thread Stéphane Mottelet
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

Re: [Scilab-users] Evaluating a polynomial on a square matrix

2019-09-24 Thread Dang Ngoc Chan, Christophe
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; "

Re: [Scilab-users] Evaluating a polynomial on a square matrix

2019-09-24 Thread Dang Ngoc Chan, Christophe
I'm aware that this is an inefficient way to compute the result but unfortunately, the Horner form of polynomial does not work on matrices: (A + 2)*A is not the same as A*A + 2*A for Scilab. It is possible to write a better function manually, by first calculating the successive powers before

Re: [Scilab-users] Evaluating a polynomial on a square matrix

2019-09-24 Thread Dang Ngoc Chan, Christophe
Hello Frederico, > De : Federico Miyara > Envoyé : mardi 24 septembre 2019 00:25 > > Is there some way of evaluating a polynomial on a square matrix in a > matrix-wise (not component-wise) fashion? You can transform your polynomial into a usual external function Then apply it to a matrix. e.g.