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); 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); 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 |
|||
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 |
|||
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 |
|||
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 |
|||
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; Code: LOCAL i,s1,s2,sx:={},sy:={}; 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; Code: LOCAL i,s1,s2,sx:={},sy:={}; Sorry for my english |
|||
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); |
|||
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 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; Anyway, getting {--1} as you had initially looks suspicious to me. |
|||
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; Hello Thank you for your answers and for the tip: Code: sx:=RANDINT(n, 0,1)*2-1; Sorry for my english |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)