[Scilab-users] Vectorization : how to proceed

Serge Steer Serge.Steer at inria.fr
Tue Nov 20 18:36:42 CET 2012


On 20/11/2012 17:28, Paul Carrico wrote:
>
> Finally I think I've found how to proceed .. at the same time I think 
> I understood the use of the dot "." (see after the cos)
>
You are right, but take care that your code will work if and only if at 
least one of i or j are scalars.
If you want your code being able to work when i and j are vectors you 
can use the kronecker product .*.

function*vect_fct*=_fct_angles_(*i*, *j*)

   i=i(:);j=j(:); //transform i and j into column vectors

*vect_fct3* = [ (cos(*i*)*.***.*sin(*j*) ), (-ones(i)*.***.*sin(*j*)), 
*i***.***.ones(j)**,***ones(i)*.***.** *j*];
endfunction


Serge Steer
>
> Paul
>
> ###################################################
>
> function*vect_fct*=_fct_angles_(*i*, *j*)
>
> *vect_fct3* = [ (cos(*i*)*.** sin(*j*) ) (-sin(*j*)) *i* *j*];
>
> endfunction
>
> B= zeros(130321,4);
>
> theta_vect= (0:360)'.*.ones(361,1);
>
> fi_vect= (ones(361,1)'.*.[0:360])';
>
> B= fct_angles3(theta_vect([1:130321],1),fi_vect([1:130321],1));
>
> *De :*users-bounces at lists.scilab.org 
> <mailto:users-bounces at lists.scilab.org> 
> [mailto:users-bounces at lists.scilab.org] *De la part de* Paul Carrico
> *Envoyé :* mardi 20 novembre 2012 14:34
> *À :* 'International users mailing list for Scilab.'
> *Objet :*[Scilab-users] Vectorization : how to proceed
>
> Dear All
>
> In the above example, how can I proceed to perform the product (see 
> function fct_angles2) ?
>
> Indeed, theta are 2 vectors, so no problem for the fct_angles ... but 
> in case of product, it's naturally not work !!! what is the correct 
> syntax in order to use vectorization ?
>
> Thanks
>
> Paul
>
> ######################################################
>
> mode(0)
>
> function *vect_fct*=_fct_angles_(*i*, *j*)
>
> *vect_fct* = [cos(*i*)+sin(*j*) -sin(*j*) *i* *j*];
>
> endfunction
>
> function *vect_fct2*=_fct_angles2_(*i*, *j*)
>
> vect_fct = [cos(*i*)*sin(*j*) -sin(*j*) *i* *j*];
>
> endfunction
>
> B1 = zeros(130321,4);
>
> theta_vect = (0:360)'.*.ones(361,1);
>
> fi_vect = (ones(361,1)'.*.[0:360])';
>
> B1 = _fct_angles_(theta_vect([1:130321],1),fi_vect([1:130321],1));
>
> B2 = _fct_angles2_(theta_vect([1:130321],1),fi_vect([1:130321],1));
>
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20121120/53efc30e/attachment.htm>


More information about the users mailing list