Polynomial program « Next Oldest | Next Newest »

 ▼ Michael Carey Junior Member Posts: 14 Threads: 4 Joined: Nov 2013 11-19-2013, 08:19 PM I have written a program to automate the process of entering a polynomial. But I am having trouble with the variables, the old variable being used previously problem I think? Here is the code: ```EXPORT QPOLY(V) BEGIN LOCAL A,Y; A:=CAS.poly2symb(V); Y:=CAS.simplify(A); END; ``` It gets upset infrequently and evaluates the whole expression to a number. For example QPLOY([1,1,1]) currently gives: 57, where it should give x^2+x+1. I have tried to clear X, but cannot seem to do so, and there is no x (lower case) in the variable list. Thank you, Michael Carey Edited: 19 Nov 2013, 8:21 p.m. ▼ Michael de Estrada Posting Freak Posts: 1,665 Threads: 142 Joined: Jan 2009 11-19-2013, 08:24 PM A and Y are predefined real variables, so you can't store symbolic results in them. Try lower case a and y. Same for V. Edited: 19 Nov 2013, 8:36 p.m. ▼ Michael Carey Junior Member Posts: 14 Threads: 4 Joined: Nov 2013 11-19-2013, 08:40 PM So I have: ```EXPORT QPOLY(v) a:=CAS.poly2symb(v); b:=CAS.simplify(a); END; ``` I get an error at b. Thank you Michael Carey ▼ Michael de Estrada Posting Freak Posts: 1,665 Threads: 142 Joined: Jan 2009 11-19-2013, 09:08 PM OK. The problem is that you can't pass a string type expression like [1,1,1] directly into the function parameter list. It is just evaluating a to 0.0, such that simplify(0) gives an error. What you need to do is first store [1,1,1] in v and then enter QPOLY(v). Also, you must create v in CAS view for this to work. Edited: 19 Nov 2013, 9:09 p.m. Eddie W. Shore Posting Freak Posts: 764 Threads: 118 Joined: Aug 2007 11-19-2013, 10:27 PM Try adding a LOCAL statement: ```EXPORT QPOLY(v) BEGIN LOCAL a,b; a:=CAS.poly2symb(v); b:=CAS.simplify(a); END; ``` ▼ Michael de Estrada Posting Freak Posts: 1,665 Threads: 142 Joined: Jan 2009 11-19-2013, 10:36 PM That will just make things worse, and the result will be 0. cyrille de Brébisson Member Posts: 193 Threads: 10 Joined: Mar 2008 11-20-2013, 03:21 AM Hello, Make this a CAS program, not a numerical program, it will help.. enter QPOLY(V):=begin simplify(poly2symb(V)); end; in CAS command line to create it (assuming that this is what you want). cyrille ▼ Michael de Estrada Posting Freak Posts: 1,665 Threads: 142 Joined: Jan 2009 11-20-2013, 09:44 AM Problem is that will only work inside CAS view. A better way that works everywhere is to write a program as follows: ```EXPORT QPOLY(v) BEGIN CAS("b:=simplify(poly2symb(v))"); RETURN b; END; ``` If v=[1,1,1], then b=x^2+x+1 Edited: 20 Nov 2013, 9:57 a.m. ▼ Michael Carey Junior Member Posts: 14 Threads: 4 Joined: Nov 2013 11-20-2013, 03:17 PM I seem to have gotten side tracked here, I should mention that that the original program *did* work, its just not working any more and I cannot work out why. I am thinking that something has stomped on the X variable, but I am not sure. Thank you Michael Carey Han Senior Member Posts: 709 Threads: 104 Joined: Nov 2005 11-20-2013, 03:33 PM Quote: I have written a program to automate the process of entering a polynomial. But I am having trouble with the variables, the old variable being used previously problem I think? Here is the code: ```EXPORT QPOLY(V) BEGIN LOCAL A,Y; A:=CAS.poly2symb(V); Y:=CAS.simplify(A); END; ``` It gets upset infrequently and evaluates the whole expression to a number. For example QPLOY([1,1,1]) currently gives: 57, where it should give x^2+x+1. I have tried to clear X, but cannot seem to do so, and there is no x (lower case) in the variable list. Thank you, Michael Carey Clearing X will have no effect on this because X is never used in the program or in any of the CAS commands used in the program. Did you mean to write lower case x? That variable, on the other hand, does affect the program. Also, x defined from CAS is different from x created in Home -- yeah, I know... what a mess ;_; I am willing to bet that there is a variable called 'x' (lower case) whose value is 7. This variable likely appears in the CAS view -- try typing: purge(x) in CAS view. CR Haeger Junior Member Posts: 37 Threads: 7 Joined: Sep 2013 11-20-2013, 04:28 PM May I ask why use a PROGRAM to automate this? Why not just use poly2symb({1,1,1}) in HOME* or CAS? In CAS poly2symb({a,2,c}) seems to allow for a combination of numbers/letters. Best, Carl * excluding RPN? Edited: 20 Nov 2013, 4:29 p.m. ▼ Michael Carey Junior Member Posts: 14 Threads: 4 Joined: Nov 2013 11-20-2013, 08:30 PM Poly2sym() doesn’t simplify. It makes it look cleaner. Ok I messed around last night before going to bed and cleared out x and now it works as intended. I am sure that I tried to do that previously though and it didn’t work. I distinctly remember getting a "No such variable x" error. Which it does now. ▼ CR Haeger Junior Member Posts: 37 Threads: 7 Joined: Sep 2013 11-20-2013, 08:43 PM In HOME view, you are right that poly2symb({1,1,1}) does not seem to simplify by itself. In CAS view, settings/simplify:maximum seems to give the simplified expression. Edited: 20 Nov 2013, 8:43 p.m.

 Possibly Related Threads... Thread Author Replies Views Last Post HP Prime: run a program in another program Davi Ribeiro de Oliveira 6 2,082 11-11-2013, 08:28 PM Last Post: Davi Ribeiro de Oliveira HP Prime polynomial long division bluesun08 13 3,042 10-30-2013, 03:29 AM Last Post: parisse [HP-Prime xCAS] Review Polynomial Tools + BUGs + Request CompSystems 0 807 09-05-2013, 12:53 PM Last Post: CompSystems Matrix Characteristic Polynomial - Reloaded. Ángel Martin 12 2,743 08-22-2013, 05:33 PM Last Post: Thomas Klemm New Blog Post: Length of a Polynomial Segment Eddie W. Shore 1 981 01-17-2013, 08:56 PM Last Post: Namir Polynomial roots again ... fhub 13 3,017 12-28-2011, 12:49 PM Last Post: fhub [WP34s] The ultimate polynomial rootsolver is here ;-) fhub 5 1,546 12-26-2011, 07:43 AM Last Post: fhub WP34S: Valentin Albillo's Polynomial Root Finder Miguel Toro 28 5,682 11-23-2011, 07:39 PM Last Post: Miguel Toro Any expert for polynomial roots here? fhub 20 3,820 11-10-2011, 01:52 PM Last Post: Peter Murphy (Livermore) Polynomial Derivative and Integral for the HP 35S Eddie W. Shore 0 1,325 05-24-2011, 10:29 PM Last Post: Eddie W. Shore

Forum Jump: