HP Forums
Produce Formular expression - 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: Produce Formular expression (/thread-20064.html)



Produce Formular expression - McQ - 06-07-2023 08:02 PM

hello Mates,
I wrote a program to make a formular from polynomial regression result.
I would like to produce something like this on Home screen:
'4*X^3+2*X^2+1'
But this is evaluated every time.

I manage to get this, only, a string (works fine):
"4*X^3+2*X^2+1"

Even to store an expression whithin the function app I was not able because I don't know how (newbie).
Here is my program code (with some output attempts at the end).
I need something what I can copy into the Function App for plotting a graph.

Please can you help me ?

EXPORT PRF(COEF)
//ERGEBNIS POLYNOMREG. ZU AUSDRUCK.
BEGIN
LOCAL I,N;
LOCAL POLYN:="";
LOCAL S:=SIZE(COEF);
N:=S(1); //LISTE {3} ZU ZAHL 3.
FOR I FROM N DOWNTO 2 DO
IF COEF[I]≠0 THEN
POLYN:=POLYN+COEF[I]+"*"+"X^"+(I-1)+"+";
END;
END;
POLYN:=POLYN+COEF[1];
PRINT(POLYN);//Output TERMINAL.
RETURN(POLYN); //Output Formular as String on Home screen
//Attempts to output Formular as expression in ' ' on Home screen; do not work;
//RETURN EXPR(POLYN); //STRING to Formula.
//QUOTE(EXPR(POLYN));
//QUOTE(POLYN);
END;


RE: Produce Formular expression - Joe Horn - 06-07-2023 08:13 PM

Just FYI, your goal can be reached without any programming. normal(POLYEVAL(coeffs,x)) in CAS returns the polynomial in x whose coefficients are in the list stored in 'coeffs'. Be sure to del(x) beforehand, or the polynomial will be evaluated using the value that's stored in x.


RE: Produce Formular expression - McQ - 06-07-2023 08:50 PM

(06-07-2023 08:13 PM)Joe Horn Wrote:  Just FYI, your goal can be reached without any programming. normal(POLYEVAL(coeffs,x)) in CAS returns the polynomial in x whose coefficients are in the list stored in 'coeffs'. Be sure to del(x) beforehand, or the polynomial will be evaluated using the value that's stored in x.

Hi Joe,
at first I did it completely wrong,now it works fine.

Do you have a proposal how I can get the result with X instead of x ? I did not manage to get a formula result while using normal(POLYEVAL(coeffs,X)) because with x (small) I cannot copy it to app Function which accepts X (big) only and the function replace seems not to work here.

very best regards
Achim


RE: Produce Formular expression - Joe Horn - 06-07-2023 11:50 PM

(06-07-2023 08:50 PM)McQ Wrote:  
(06-07-2023 08:13 PM)Joe Horn Wrote:  Just FYI, your goal can be reached without any programming. normal(POLYEVAL(coeffs,x)) in CAS returns the polynomial in x whose coefficients are in the list stored in 'coeffs'. Be sure to del(x) beforehand, or the polynomial will be evaluated using the value that's stored in x.

Hi Joe,
at first I did it completely wrong,now it works fine.

Do you have a proposal how I can get the result with X instead of x ? I did not manage to get a formula result while using normal(POLYEVAL(coeffs,X)) because with x (small) I cannot copy it to app Function which accepts X (big) only and the function replace seems not to work here.

very best regards
Achim

In Home (and in ordinary, non-CAS programs) try this:

CAS.normal(POLYEVAL(coeffs,'X'))

The leading "CAS." forces the following expression to be run by CAS, and the single quotation marks around the 'X' tell Prime to leave 'X' in symbolic form and not to replace it with its stored value.


RE: Produce Formular expression - McQ - 06-08-2023 01:35 AM

Works fantastic. Thank you very much, Joe !!!


RE: Produce Formular expression - thenozone - 06-08-2023 07:44 AM

Thanks Joe; that last bit was one of the most useful things any one showed me for the prime.