[Scilab-users] vectorization difficulty

Stéphane Mottelet stephane.mottelet at utc.fr
Fri Jan 18 15:21:49 CET 2019


Hello Paul,

If you stick to 3x3, you can vectorize the Cardan formulas applied to 
the characteristic polynomial of each individual matrix.

S.



Le 15/01/2019 à 09:56, Carrico, Paul a écrit :
>
> clc
>
> mode(0)
>
> clear
>
> function*V*=_eigen_val_(*S11*, *S12*, *S13*, *S22*, *S23*, *S33*)
>
> S_u = [0 *S12* *S13* ; 0 0 *S23* ; 0. 0. 0.];
>
> S_d = [*S11* ; *S22* ; *S33*];
>
> S = S_u + S_u' + diag(S_d);
>
> *V* = gsort(spec(S),'lr','d')'; clear S; clear S_u; clear S_d;
>
> endfunction
>
> n= 10; m = 1;
>
> S11= rand(n,m);
>
> S22= rand(n,m);
>
> S33= rand(n,m);
>
> S12= rand(n,m);
>
> S23= rand(n,m);
>
> S13= rand(n,m);
>
> princ= zeros(n,3);
>
> /// with a loop/
>
> tic();
>
> princ1= zeros(n,3*m);
>
> fori = 1 : n
>
> S_u = [0 S12(i,m) S13(i,m) ; 0 0 S23(i,m) ; 0. 0. 0.];
>
> S_d = [S11(i,m) ; S22(i,1) ; S33(i,m)];
>
> S = S_u + S_u' + diag(S_d);
>
> princ1(i,:) = gsort(spec(S),'lr','d')'; clear S; clear S_u; clear S_d;
>
> end
>
> duration1= toc(); printf("Duration 1 = %g\n",duration1);
>
> /// using a function/
>
> tic();
>
> princ2= zeros(n,3*m);
>
> fori = 1 : n
>
> princ2(i,:) = 
> _eigen_val_(S11(i,m),S12(i,m),S13(i,m),S22(i,m),S23(i,m),S33(i,m));
>
> end
>
> duration2= toc(); printf("Duration 2 = %g\n",duration2);
>
> isequal(princ1,princ2)
>
> /// using vectorization (in combination with the function ?)/
>
> i= (1:n)';
>
> S= zeros(3,3,n)


-- 
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20190118/84105a95/attachment.htm>


More information about the users mailing list