problem with CHS - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: problem with CHS (/thread-12531.html) |
problem with CHS - Tyann - 03-01-2019 09:22 AM 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. RE: problem with CHS - StephenG1CMZ - 03-01-2019 01:42 PM 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...') RE: problem with CHS - rprosperi - 03-01-2019 01:56 PM Or, just use: sy(I):=sy(I) * -1; It seems in the original use, "-" is treated as an operator rather than unary minus. RE: problem with CHS - Tyann - 03-01-2019 02:44 PM 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. RE: problem with CHS - Tyann - 03-01-2019 05:26 PM 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:={}; RE: problem with CHS - Albert Chan - 03-01-2019 06:56 PM 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); RE: problem with CHS - Didier Lachieze - 03-01-2019 09:49 PM (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. RE: problem with CHS - Tyann - 03-02-2019 05:50 AM 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; |