Produce Formular expression
|
06-07-2023, 08:02 PM
Post: #1
|
|||
|
|||
Produce Formular expression
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; |
|||
06-07-2023, 08:13 PM
Post: #2
|
|||
|
|||
RE: Produce Formular expression
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.
<0|ɸ|0> -Joe- |
|||
06-07-2023, 08:50 PM
(This post was last modified: 06-07-2023 09:15 PM by McQ.)
Post: #3
|
|||
|
|||
RE: Produce Formular expression
(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 |
|||
06-07-2023, 11:50 PM
Post: #4
|
|||
|
|||
RE: Produce Formular expression
(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. 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. <0|ɸ|0> -Joe- |
|||
06-08-2023, 01:35 AM
Post: #5
|
|||
|
|||
RE: Produce Formular expression
Works fantastic. Thank you very much, Joe !!!
|
|||
06-08-2023, 07:44 AM
Post: #6
|
|||
|
|||
RE: Produce Formular expression
Thanks Joe; that last bit was one of the most useful things any one showed me for the prime.
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)