Polynomial program



#14

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.


#15

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.


#16

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


#17

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.

#18

Try adding a LOCAL statement:

EXPORT QPOLY(v)
BEGIN
LOCAL a,b;
a:=CAS.poly2symb(v);
b:=CAS.simplify(a);
END;

#19

That will just make things worse, and the result will be 0.

#20

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


#21

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.


#22

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

#23

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.

#24

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.


#25

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.


#26

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,733 11-11-2013, 08:28 PM
Last Post: Davi Ribeiro de Oliveira
  HP Prime polynomial long division bluesun08 13 3,724 10-30-2013, 03:29 AM
Last Post: parisse
  [HP-Prime xCAS] Review Polynomial Tools + BUGs + Request CompSystems 0 981 09-05-2013, 12:53 PM
Last Post: CompSystems
  Matrix Characteristic Polynomial - Reloaded. Ángel Martin 12 3,530 08-22-2013, 05:33 PM
Last Post: Thomas Klemm
  New Blog Post: Length of a Polynomial Segment Eddie W. Shore 1 1,212 01-17-2013, 08:56 PM
Last Post: Namir
  Polynomial roots again ... fhub 13 3,734 12-28-2011, 12:49 PM
Last Post: fhub
  [WP34s] The ultimate polynomial rootsolver is here ;-) fhub 5 1,918 12-26-2011, 07:43 AM
Last Post: fhub
  WP34S: Valentin Albillo's Polynomial Root Finder Miguel Toro 28 7,258 11-23-2011, 07:39 PM
Last Post: Miguel Toro
  Any expert for polynomial roots here? fhub 20 4,986 11-10-2011, 01:52 PM
Last Post: Peter Murphy (Livermore)
  Polynomial Derivative and Integral for the HP 35S Eddie W. Shore 0 1,486 05-24-2011, 10:29 PM
Last Post: Eddie W. Shore

Forum Jump: