[Scilab-users] function and vectorization
Stéphane Mottelet
stephane.mottelet at utc.fr
Wed Nov 7 13:39:43 CET 2018
Hello,
Try:
function [Scar_P]=Scalar_product(C, N, M) // Scalar product
Scar_P = (M(:,1) - C(:,1)).*(N(:,1) - C(:,1)) + (M(:,2) - C(:,2)).*(N(:,2) - C(:,2));
//printf("C = (%g,%g)\n",C(1),C(2)); printf("N = (%g,%g)\n",N(1),N(2));
printf("M = (%g,%g)\n",M(1),M(2));
endfunction with (do not transpose N(i,1:2))
i= 1 : n;
Scal(i)= _Scalar_product_(C(i,:),N(i,1:2),M(i,:))
S.
Le 07/11/2018 à 12:35, Carrico, Paul a écrit :
>
> #####################################################################
>
> mode(0)
>
> clear
>
> function[*Scar_P*]=_Scalar_product_(*C*, *N*, *M*) /// Scalar product/
>
> *Scar_P* = (*M*(1) - *C*(1))*(*N*(1) - *C*(1)) + (*M*(2) -
> *C*(2))*(*N*(2) - *C*(2));
>
> printf("C = (%g,%g)\n",*C*(1),*C*(2)); printf("N =
> (%g,%g)\n",*N*(1),*N*(2)); printf("M = (%g,%g)\n",*M*(1),*M*(2));
>
> endfunction
>
> n= 10;
>
> C= rand(n,2);
>
> M= rand(n,2);
>
> N= rand(n,5);
>
> Scal= zeros(n); Scal2 = Scal
>
> printf(" ****************\n");
>
> i= 1 : n;
>
> Scal(i)= _Scalar_product_(C(i,:),N(i,1:2)',M(i,:))
>
> printf("\n ****************\n");
>
> fori = 1 : n
>
> Scal2(i) = _Scalar_product_(C(i,:),N(i,1:2)',M(i,:));
>
> end
>
--
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/20181107/1870cad7/attachment.htm>
More information about the users
mailing list