Post Reply 
Problem on displaying user defined function as output
11-03-2022, 09:09 AM
Post: #3
RE: Problem on displaying user defined function as output
(11-02-2022 08:20 PM)ftneek Wrote:  Assuming the coefficients are stored in L0, you could try this:
Code:

return Σ(L0(I)*FALL(I-1),I,1,DIM(L0));

It may need to be a cas program to give a symbolic result. Let me know if it works

Thank you for replying, I have tried similar idea but as FALL(n) has been implemented, it would directly simplify to some products like: FALL(4,x) ---->x*(x-1)*(x-2)*(x-3).

So my idea is to use string manipulation, may be a bit clumsy as follows:
Code:

#cas
//convert a list of coeff with unknown x into a string of FALL(n,x)
coeff2fall(coeff,x):=
BEGIN
LOCAL Q, n;
Q:="";
n:=length(coeff);
FOR K FROM 0 TO n-1 STEP 1 DO
CASE
IF coeff[K+1]>0 THEN Q:= Q + "+" + coeff[K+1] + "*FALL(" + K + "," + x + ")" END;
IF coeff[K+1]<0 THEN Q:= Q + coeff[K+1] + "*FALL(" + K + "," + x + ")" END; 
DEFAULT Q:=Q;
END;
END;
RETURN Q;
END;
#end

The result is good,
input: COEFF2FALL(x,{0,1,7,6,1})
output:"+1*FALL(1,x)+7*FALL(2,x)+6*FALL(3,x)+1*FALL(4,x)"

The only downside is the additional quotation marks, expr is need to further use. I am not sure if the output could be produced without "".
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Problem on displaying user defined function as output - gamma057721 - 11-03-2022 09:09 AM



User(s) browsing this thread: 1 Guest(s)