[scilab-Users] vector elementwise division 1./[1 2 3 4]

Francis Drossaert Francis.Drossaert at pgs.com
Tue Sep 2 11:13:58 CEST 2008


You could also use

1../v1
[1]./v1 

the latter one is probably the most elegant one since ./ is a vector operation and writing the integer as a vector would adhere to the operation. But I have to agree it is a pitfall, which is not easy to debug since it gives a solution albeit a wrong one.

Cheers,

Francis


-----Original Message-----
From: Antoine ELIAS [mailto:antoine.elias at scilab.org] 
Sent: 02 September 2008 10:00
To: users at lists.scilab.org
Subject: Re: [scilab-Users] vector elementwise division 1./[1 2 3 4]

Hi Bagvian,

Yes it's strange but "normal' :D
Scilab's parser tries to interpret "1." and after "/V1"
So for Scilab you try to divide 1.0 ( floating point value ) by V1 ( not element wise ) To be sure Scilab use "./" operator, add spaces around operator like "1 ./ V1"

Regards,
Antoine ELIAS

bagvian a écrit :
> Hi,
>
> Old Matlab user, I wanted to create a simple row vector (say V1) and 
> inverse each of its components with the values to be set in another 
> row vector (say V2). I typed in Scilab prompt:
>
> V1=[1 2 3 4] ;
>
> V2=1./V1
>
> I obtained :
>
> V2 =
>
> 0.0333333
>
> 0.0666667
>
> 0.1
>
> 0.1333333
>
> Amazing, isn't?
>
> In order to get the result I expected, I had to type :
>
> V2=(1)./V1
>
> To obtain:
>
> V2 =
>
> 1. 0.5 0.3333333 0.25
>
> Don't you find this behaviour rather inappropriate?
>
> Thanks for your comments, Bagvian
>   


This email and any files contained therein is confidential and may contain privileged information.  If you are not the named addressee(s) or you have otherwise received this in error, you should not distribute or copy this e-mail or use any of its content for any purpose. Please notify the sender immediately by e-mail if you have received this e-mail in error and delete it from your system



More information about the users mailing list