[Scilab-users] unexpected result

classic Classic list List threaded Threaded
6 messages Options
Carrico, Paul-2 Carrico, Paul-2
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] unexpected result

Hi All,

 

In the following code, I was thinking that the provided index was the one on the “global” matrix, but I was wrong J

(I guess a copy is performed first in order to be more efficient and to speed-up the calculation)

 

Paul

 

n = 10;

B = ones(n,1);

i = 6;

B(i,1)=0.55;

a1 = find(B(:,1) < 1); disp(a1);

a2 = find(B(i-1:$,1) < 1); disp(a2);

 

 

 


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: unexpected result

Hello Paul,

B(i-1:$,1) in a rhs is evaluated as a temporary 6x1 vector when passed as an argument to find() and any reference w.r.t. B is of course disgarded.

The obtained result is the expected result.

S.

Le 22/05/2019 à 09:51, Carrico, Paul a écrit :

Hi All,

 

In the following code, I was thinking that the provided index was the one on the “global” matrix, but I was wrong J

(I guess a copy is performed first in order to be more efficient and to speed-up the calculation)

 

Paul

 

n = 10;

B = ones(n,1);

i = 6;

B(i,1)=0.55;

a1 = find(B(:,1) < 1); disp(a1);

a2 = find(B(i-1:$,1) < 1); disp(a2);

 

 

 


_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Christophe Dang Ngoc Chan Christophe Dang Ngoc Chan
Reply | Threaded
Open this post in threaded view
|

Re: {EXT} unexpected result

In reply to this post by Carrico, Paul-2
Hello Paul,

> De : Carrico, Paul
> Envoyé : mercredi 22 mai 2019 09:51
>
> In the following code,
> I was thinking that the provided index was the one on the “global”
> matrix, but I was wrong ☺ […]
> a2 = find(B(i-1:$,1) < 1); disp(a2);

I would have made the same mistake (-:

Now if we look at the documentation
https://help.scilab.org/docs/6.0.2/en_US/extraction.html
we read "r=x(i,j) builds the matrix r such as […]"

and
https://help.scilab.org/docs/6.0.2/en_US/find.html
"If x is a boolean matrix, ii=find(x) returns […]"

so the behaviour seems quite logical.

But it might be a good idea to provide an example such as yours in the documentation, at least to preserve our injured self-esteem (we are not the only two who have been fooled).

Regards

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer

General
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Carrico, Paul-2 Carrico, Paul-2
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Re: {EXT} unexpected result

Hi all for the feedback

Indeed it's logical afterward, and it has been made to be fast and efficient ... but I spent a lot of time in finding my mistake that it uses a "local/temporary" index than a "global" one.

I share your suggestion in adding an example in the doc to prevent Scilab users, but the question is "where" ?

Paul



-----Message d'origine-----
De : users [mailto:[hidden email]] De la part de Dang Ngoc Chan, Christophe
Envoyé : jeudi 23 mai 2019 09:14
À : Users mailing list for Scilab
Objet : [EXTERNAL] Re: [Scilab-users] {EXT} unexpected result

Hello Paul,

> De : Carrico, Paul
> Envoyé : mercredi 22 mai 2019 09:51
>
> In the following code,
> I was thinking that the provided index was the one on the “global”
> matrix, but I was wrong ☺ […]
> a2 = find(B(i-1:$,1) < 1); disp(a2);

I would have made the same mistake (-:

Now if we look at the documentation
https://urldefense.proofpoint.com/v2/url?u=https-3A__help.scilab.org_docs_6.0.2_en-5FUS_extraction.html&d=DwIGaQ&c=0hKVUfnuoBozYN8UvxPA-w&r=2R_Eyw3woK4XVPnEug_8oZFQfCE8Ul6UYufxQizYx6k&m=h_9KPbMv5WwpOSsz29HjgLF8hOXdEKk2R2dkyVy334w&s=zrjH9zC_wmeR2sNsnm6LqAH5OhklVr2sn_50F2Z1Fjo&e=
we read "r=x(i,j) builds the matrix r such as […]"

and
https://urldefense.proofpoint.com/v2/url?u=https-3A__help.scilab.org_docs_6.0.2_en-5FUS_find.html&d=DwIGaQ&c=0hKVUfnuoBozYN8UvxPA-w&r=2R_Eyw3woK4XVPnEug_8oZFQfCE8Ul6UYufxQizYx6k&m=h_9KPbMv5WwpOSsz29HjgLF8hOXdEKk2R2dkyVy334w&s=OYg1le1-U4zV-uuw5ELo1kH_6ne9heq4jXFovUh3B0o&e=
"If x is a boolean matrix, ii=find(x) returns […]"

so the behaviour seems quite logical.

But it might be a good idea to provide an example such as yours in the documentation, at least to preserve our injured self-esteem (we are not the only two who have been fooled).

Regards

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer

General
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________
users mailing list
[hidden email]
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.scilab.org_mailman_listinfo_users&d=DwIGaQ&c=0hKVUfnuoBozYN8UvxPA-w&r=2R_Eyw3woK4XVPnEug_8oZFQfCE8Ul6UYufxQizYx6k&m=h_9KPbMv5WwpOSsz29HjgLF8hOXdEKk2R2dkyVy334w&s=X2P0bkSUBEv9LsNxFZbxr_BvXqso_YMPWQxb7TWdNgw&e=
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Christophe Dang Ngoc Chan Christophe Dang Ngoc Chan
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Re: {EXT} unexpected result

Hello,

> De : Carrico, Paul
> Envoyé : jeudi 23 mai 2019 09:21
>
> I share your suggestion in adding an example in the doc to prevent Scilab
> users, but the question is "where" ?

I suggest the "Scilab Help >> Elementary Functions > extraction" page.

Regards

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer

General
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Re: {EXT} unexpected result

Le 23/05/2019 à 09:34, Dang Ngoc Chan, Christophe a écrit :
Hello,

De : Carrico, Paul
Envoyé : jeudi 23 mai 2019 09:21

I share your suggestion in adding an example in the doc to prevent Scilab
users, but the question is "where" ?
I suggest the "Scilab Help >> Elementary Functions > extraction" page.

I am not sure that is the right place. In fact our discussion is about the general concepts of lvalue and rvalue (in most languages, compiled or interpreted, see e.g. https://www.quora.com/What-is-lvalue-and-rvalue-in-C which starts with general stuff valuable for Scilab also)

In this insertion expression:

x(i) = y

x(i) determines the identity of an object, and we need this because the evaluation of the expression will modify it . In this case "x(i)" is a lvalue. The "l" is to recall that such constructs are to the left of the assignment operator

In this extraction expression:

y = x(i)

"x(i)" is a rvalue, i.e. a "result"  which is  temporary materialized, and identity of x is lost (because we don't need it). Here the "r" can be seen as "right" as well as "result" (I prefer "result"...)

Hence, in the expressions

x=rand(10,1);
[v,k]=find(x(3:10))

find() just sees an anonymous/temporary 8x1 vector. It is the user's responsibility to do

k=k+2

to compute the actual index in original vector.

S.


Regards

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer

General
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users


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

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users