Post Reply 
problem with CHS
03-01-2019, 09:22 AM
Post: #1
problem with CHS
Bonjour
Dans un programme que je suis en train d'écrire je reçois un message d'erreur :argument incorrect qui ne se déclenche pas tout le temps dans la ligne suivante :
by:=y(I)+14*(sy(I)>0);
Cette ligne est dans une boucle FOR I
y et sy sont des listes de dimension minimum de 1 élément.
sy(I) est une valeur qui alterne entre 1 et -1 avec le code suivant sy(I):=-sy(I);
lorsque je place un DEBUG() avant cette ligne et que je visualise sy, je vois {---1}
et c'est je pense ce qui déclenche l'erreur.
Est-ce un bug ?
Y a t il une solution ?
Toute aide est la bienvenue.
merci.

Hello
In a program that I am writing I receive an error message: incorrect argument that does not fire all the time in the following line:
Code:
by:=y(I)+14*(sy(I)>0);
This line is in a FOR I loop
y and sy are lists of minimum dimension of 1 element.
sy (I) is a value that alternates between 1 and -1 with the following code :
Code:
 sy(I):=-sy(I);
when I put a DEBUG () before this line and I visualize sy, I see {--- 1}
and that's what I think triggers the error.
Is this a bug?
Is there a solution ?
Any help is welcome.
thank you.

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-01-2019, 01:42 PM (This post was last modified: 03-01-2019 01:56 PM by StephenG1CMZ.)
Post: #2
RE: problem with CHS
Have you tried wrapping what is after the negate in an extra pair of parentheses?
- (sy(I))

Alternatively, try using cas neg:
Sy(I) :=neg(sy(I)) or
Sy(I) :=CAS('neg...')

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
03-01-2019, 01:56 PM
Post: #3
RE: problem with CHS
Or, just use:

sy(I):=sy(I) * -1;

It seems in the original use, "-" is treated as an operator rather than unary minus.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
03-01-2019, 02:44 PM
Post: #4
RE: problem with CHS
Merci pour vos réponse, je viens d'essayer les 2 solutions, à vrai dire j'avais pensé au *-1.
Ceci dit, même résultat, lorsque sy renvoie {-1} :cela fonctionne mais lorsque sy renvoie {--1} cela provoque l'erreur.
Je pense que je vais essayer d'utiliser : sy(I):=IFTE(sy(I)>0,-1,1);
Cela devrait résoudre normalement le problème.
Encore merci à vous 2.


Thank you for your answer, I just tried both solutions, actually I had thought of * -1.
That said, same result, when sy returns {-1}: it works but when sy returns {--1} it causes the error.
I think I'll try to use: sy (I): = IFTE (sy (I)> 0, -1,1);
This should solve the problem normally.
Thank you again 2.

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-01-2019, 05:26 PM (This post was last modified: 03-01-2019 05:28 PM by Tyann.)
Post: #5
RE: problem with CHS
J'ai je pense enfin résolu mon problème, plus d'erreur depuis plusieurs essais maintenant.
Voilà ce que j'ai cru comprendre :
Le problème venait apparement de l'initialisation de sx et sy qui était fait comme ceci:
soit 'n' le nombre d'éléments des 2 listes, le but étant d'avoir des valeurs -1 ou 1 au hasard.
Code:
LOCAL s,sx,sy;
s:=RANDINT(n,1,10);sx:=IFTE(s>5,1,-1); 
s:=RANDINT(n,1,10);sy:=IFTE(s>5,1,-1);
et que j'ai transformé en :
Code:
LOCAL i,s1,s2,sx:={},sy:={};
s1:=RANDINT(n,1,10);
s2:=RANDINT(n,1,10);
FOR i FROM 1 TO n DO
 sx(0):=IFTE(s1(i)>5,1,-1);
 sy(0):=IFTE(s2(i)>5,1,-1);
END;
J'avais pourtant testé la première méthode dans Home avant de le programmer et cela fonctionnait ?


I think I finally solved my problem, more error for several tries now.
This is what I understand:
The problem apparently came from the initialization of sx and sy which was done like this:
either 'n' the number of elements of the 2 lists, the goal being to have values ​​-1 or 1 at random.
Code:
LOCAL s,sx,sy;
s:=RANDINT(n,1,10);sx:=IFTE(s>5,1,-1); 
s:=RANDINT(n,1,10);sy:=IFTE(s>5,1,-1);
and that I turned into:
Code:
LOCAL i,s1,s2,sx:={},sy:={};
s1:=RANDINT(n,1,10);
s2:=RANDINT(n,1,10);
FOR i FROM 1 TO n DO
 sx(0):=IFTE(s1(i)>5,1,-1);
 sy(0):=IFTE(s2(i)>5,1,-1);
END;
But I had tested the first method in Home before programming it and it worked ?

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-01-2019, 06:56 PM
Post: #6
RE: problem with CHS
On XCas, rand(n, 1, 10) does not really meant n random numbers, ranged 1 to 10

I think it meant n random samples from list 1 to 10, thus all elements are unique.
If I try rand(10, 1, 2), XCas session is *crashed*

The random sign sx, sy list may be shortened as 1 liner:

[sx, sy] := makemat(x -> rand(2)*2 - 1, 2, n);
Find all posts by this user
Quote this message in a reply
03-01-2019, 09:49 PM
Post: #7
RE: problem with CHS
(03-01-2019 06:56 PM)Albert Chan Wrote:  On XCas, rand(n, 1, 10) does not really meant n random numbers, ranged 1 to 10

I think it meant n random samples from list 1 to 10, thus all elements are unique.

RANDINT(a,b,c) which is a home function, returns a list of size a with each element being a random integer x from b to c. The elements are not unique.

(03-01-2019 06:56 PM)Albert Chan Wrote:  [sx, sy] := makemat(x -> rand(2)*2 - 1, 2, n);

With the same logic and using RANDINT :
Code:
sx:=RANDINT(n,0,1)*2-1;
sy:=RANDINT(n,0,1)*2-1;

Anyway, getting {--1} as you had initially looks suspicious to me.
Find all posts by this user
Quote this message in a reply
03-02-2019, 05:50 AM (This post was last modified: 03-02-2019 05:51 AM by Tyann.)
Post: #8
RE: problem with CHS
Bonjour

Merci de vos de réponses et pour l'astuce :
Code:
sx:=RANDINT(n,0,1)*2-1;
que j'ai adopté .


Hello

Thank you for your answers and for the tip:
Code:
 sx:=RANDINT(n, 0,1)*2-1;
which I adopted.

Sorry for my english
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)