hello The question is :
How to substitute n floating values for the n variables of a polynomial in Sage, where n is a variable ? For example, Let P P=x3*x6+x1*x6+x4*x5+x2*x5+x1*x4+x2* and f=x^6+2 with approximate roots rr=gp.polroots(f) =[0.9720806486198328151427283823 + 0.5612310241546864907167665248*I, 0.9720806486198328151427283823 - 0.5612310241546864907167665248*I, 0.E-36 + 1.122462048309372981433533050*I, 0.E-36 - 1.122462048309372981433533050*I, -0.9720806486198328151427283823 + 0.5612310241546864907167665248*I, -0.9720806486198328151427283823 - 0.5612310241546864907167665248*I] We want to substitute in P the n=6 values contained in rr for the variables xi. P(rr[0],rr[1],rr[2],rr[3],rr[4],rr[5]) is not convenient because we want P(rr[0],rr[1],rr[2],...,rr[n]) and to know how to construct the series rr[0],rr[1],rr[2],...,rr[n] ? The substitution may be performed as follows : ************************ n=6 for i in range(1,n+1): p2=P.subs({x[i]:rr[i]}) result: (x5 + (0.9720806486198328151427283823 +0.5612310241546864907167665248*I))*x4 + ((x5 + x3)*x2 + (x3 +(0.9720806486198328151427283823 + 0.5612310241546864907167665248*I))*x6) ********************************** But just the first variable is substituted. A type problem w.r.t. the coefficients ? When the degree n of f is know, We can also substitute using the following command RESULT1= P.subs({x[1]:rr[0],x[2]:rr[1],x[3]:rr[2],x[4]:rr[3],x[5]:rr [4],x[6]:rr[5]}) 1.259921049894873164767210607 - 2.524354897 E-29*I But in a program the degree of f is n and not necessarily 6. The problem is to construct x[1]:rr[0],x[2]:rr[1],x[3]:rr[2],x[4]:...,x[n]:rr[n-1] when n is a variable. Moreover, We have used the map fonction of maxima in order to construct a substitution list for the maxima.subst fonction: ****************************** n=6 v=maxima.map('lambda([rac,i],concat(x,i)=rac)',rr,'makelist(i,i, 1,n)');v RESULT2 = gp(maxima.subst(v,P)); 1.259921049894873327847796133 + 2.524354897 E-29*I ************************* However, result RESULT2 is not the desired result RESULT1 computed with the subs fonction of Sage (derived from the subst fonction of maxima) because maxima troncates the float: *********************** rr[0] 0.9720806486198328151427283823 + 0.5612310241546864907167665248*I with maxima rr[0] is troncated: maxima(rr[0]) .5612310241546865*I+.9720806486198328 ********************************************* The only solution is to extend the precision of the floats of maxima ? And how in Sage (not in maxima) ? It is very complicated ! We think that it is not a nice solution. Can you help us ? Best regards, Faical Bouazizi and Annick Valibouze --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---