Polynomial program  Printable Version + HP Forums (https://archived.hpcalc.org/museumforum) + Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum1.html) + Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum2.html) + Thread: Polynomial program (/thread256414.html) 
Polynomial program  Michael Carey  11192013 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)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.
Re: Polynomial program  Michael de Estrada  11192013 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.
Re: Polynomial program  Michael Carey  11192013 So I have:
EXPORT QPOLY(v)I get an error at b.
Thank you Michael Carey
Re: Polynomial program  Michael de Estrada  11192013 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.
Re: Polynomial program  Eddie W. Shore  11192013 Try adding a LOCAL statement:
EXPORT QPOLY(v) Re: Polynomial program  Michael de Estrada  11192013 That will just make things worse, and the result will be 0.
Re: Polynomial program  cyrille de Brébisson  11202013 Hello, Make this a CAS program, not a numerical program, it will help..
enter
cyrille
Re: Polynomial program  Michael de Estrada  11202013 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) If v=[1,1,1], then b=x^2+x+1
Edited: 20 Nov 2013, 9:57 a.m.
Re: Polynomial program  Michael Carey  11202013 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
Re: Polynomial program  Han  11202013 Quote: 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.
Re: Polynomial program  CR Haeger  11202013 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,
* excluding RPN? Edited: 20 Nov 2013, 4:29 p.m.
Re: Polynomial program  Michael Carey  11202013 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.
Re: Polynomial program  CR Haeger  11202013 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.
