[sage-support] Re: how to factorize an expression with constant variables ?
sorry for the late answer. After some investigations on the internet, I did not find any convenient solution. My concern being on polynomials, I ended up doing some copy/paste of my expressions and working in another window with a polynomial ring defined the following way : R.A,B = QQ[] R.x,y,z = PolynomialRing(QQ[A,B],order='deglex') where x, y, z are the variables and A, B some parameters. It's not very nice because I have to do some copy/paste, but at least I had my answer at the end. Best regards. -- You received this message because you are subscribed to the Google Groups sage-support group. 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. Visit this group at http://groups.google.com/group/sage-support?hl=en.
[sage-support] Re: Notebook evaluate fails return: OSX 10.6.8
I had the same problem and deleting the 'sage_notebook.sagenb' directory from '~/.sage/' resolved it. Thanks for the tip. -- You received this message because you are subscribed to the Google Groups sage-support group. 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. Visit this group at http://groups.google.com/group/sage-support?hl=en.
[sage-support] how to factorize an expression with constant variables ?
Hello, I would like to factorize an expression with sage that contains constant variables (i.e. parameters), but I cannot figure out how to do that. Here is an example : x, y are variables and A is a parameter * var('A x y') f = A*x + x + A^2*exp(y) + y print (f.factor()) * Sage returns 'A^2*e^y + A*x + x + y'. Instead, I would like that sage returns '(A+1)*x + (A^2+1)*exp(y)'. How to do that ? Thank you -- You received this message because you are subscribed to the Google Groups sage-support group. 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. Visit this group at http://groups.google.com/group/sage-support?hl=en.
[sage-support] Sage gives a wrong taylor expansion
Hello, I used sage to find the root (named P2plus) of an equation. The variable is P1plus and there are 3 parameters, M1, M2 and gamma. The expression of the root (P2plus) being complicated, and as I am interested in its behavior for small values of P1plus, I asked Sage for the Taylor expansion (2nd order) of P2plus. The problem is, when I plot the initial expression of P2plus and its Taylor expansion, one can clearly see that the expressions differ near P1plus=0. In other words, the Taylor expansion given by Sage seems to be erroneous. The root P2plus being a fraction, I looked at the Taylor expansions of the numerator and denominator. It appears that the Taylor expansion of the numerator is erroneous. But I can't figure out why. Here is my code. Is there any error in it or am I doing something wrong while asking for the Taylor expansion ? Any help would be greatly appreciated. Thanks Maxime P1plus = var('P1plus') M1 = var('M1') M2 = var('M2') gamma = var('gamma') P2plus_init = (M1^3*M2^2*gamma + M1^2*M2^3*gamma + 2*M1*M2^3*P1plus*gamma - M1^3*M2^2 + M1^3*M2*gamma - M1^2*M2^3 - 2*M1*M2^3*P1plus - M1*M2^3*gamma + 2*M1*M2^2*P1plus*gamma - M1^3*M2 - M1^2*M2*gamma + M1*M2^3 - 2*M1*M2^2*P1plus - M1*M2^2*gamma + 3*M1^2*M2 + 3*M1*M2^2 + 4*M1*M2*P1plus + 2*M1^2 + 4*M1*P1plus - 2*M1 - 2*M2 + sqrt((M1^4*P1plus^2 + 2*(2*P1plus^3 - P1plus^2)*M1^3 + (4*P1plus^4 - 4*P1plus^3 + P1plus^2)*M1^2)*M2^6*gamma^4 + ((P1plus^2 + 4*P1plus + 1)*M1^4 + 2*(2*P1plus^3 + 6*P1plus^2 - 1)*M1^3 + (4*P1plus^4 + 12*P1plus^3 + P1plus^2 - 8*P1plus + 1)*M1^2 + 2*(4*P1plus^4 - 5*P1plus^2 + 2*P1plus)*M1)*M2^6 + 2*((P1plus^2 + 6*P1plus - 1)*M1^4 + M1^5 + (4*P1plus^3 + 12*P1plus^2 - 2*P1plus - 3)*M1^3 + (4*P1plus^4 + 12*P1plus^3 + P1plus^2 - 12*P1plus + 5)*M1^2 + 2*(4*P1plus^4 - 5*P1plus^2 + 4*P1plus - 1)*M1)*M2^5 + (M1^6 - 2*(2*P1plus^2 + 4*P1plus + 7)*M1^4 + 2*M1^5 - 2*(8*P1plus^3 + 24*P1plus^2 + 2*P1plus - 5)*M1^3 - (16*P1plus^4 + 48*P1plus^3 - 12*P1plus - 13)*M1^2 - 8*(4*P1plus^4 - 5*P1plus^2 + 2)*M1 + 4)*M2^4 + 8*(2*P1plus - 1)*M1^3 - 2*((2*(P1plus^2 + P1plus)*M1^4 + (8*P1plus^3 + 3*P1plus^2 - 2*P1plus)*M1^3 + 2*(4*P1plus^4 - P1plus)*M1^2 + (4*P1plus^4 - 5*P1plus^2 + 2*P1plus)*M1)*M2^6 + (M1^4*P1plus^2 + 2*(2*P1plus^3 - P1plus^2)*M1^3 + (4*P1plus^4 - 4*P1plus^3 + P1plus^2)*M1^2)*M2^5 - 2*(M1^4*P1plus^2 + 2*(2*P1plus^3 - P1plus^2)*M1^3 + (4*P1plus^4 - 4*P1plus^3 + P1plus^2)*M1^2)*M2^4)*gamma^3 + 2*(M1^6 - (4*P1plus^2 + 18*P1plus + 5)*M1^4 - 3*M1^5 - (16*P1plus^3 + 48*P1plus^2 - 2*P1plus - 17)*M1^3 - 4*(4*P1plus^4 + 12*P1plus^3 + P1plus^2 - 9*P1plus + 2)*M1^2 - 2*(16*P1plus^4 - 20*P1plus^2 + 10*P1plus + 3)*M1 + 4)*M2^3 + 4*M1^4 + 4*(4*P1plus^2 - 4*P1plus + 1)*M1^2 + (((6*P1plus^2 + 12*P1plus + 1)*M1^4 + 2*(12*P1plus^3 + 15*P1plus^2 - 4*P1plus - 1)*M1^3 + (24*P1plus^4 + 24*P1plus^3 - 2*P1plus^2 - 16*P1plus + 1)*M1^2 + 6*(4*P1plus^4 - 5*P1plus^2 + 2*P1plus)*M1)*M2^6 + 2*((3*P1plus^2 + 6*P1plus - 1)*M1^4 + M1^5 + (12*P1plus^3 + 8*P1plus^2 - 2*P1plus - 1)*M1^3 + (12*P1plus^4 + 4*P1plus^3 + 3*P1plus^2 - 8*P1plus + 1)*M1^2 + 2*(4*P1plus^4 - 5*P1plus^2 + 2*P1plus)*M1)*M2^5 + (M1^6 - 2*(6*P1plus^2 + 4*P1plus + 3)*M1^4 + 2*M1^5 - 2*(24*P1plus^3 + 16*P1plus^2 - 6*P1plus - 1)*M1^3 - (48*P1plus^4 + 16*P1plus^3 - 8*P1plus^2 - 12*P1plus - 1)*M1^2 - 8*(4*P1plus^4 - 5*P1plus^2 + 2*P1plus)*M1)*M2^4 + 2*(M1^6 - (4*P1plus^2 - 2*P1plus + 1)*M1^4 - M1^5 - (16*P1plus^3 - 8*P1plus^2 + 2*P1plus - 1)*M1^3 - 4*(4*P1plus^4 - 4*P1plus^3 + P1plus^2)*M1^2)*M2^3 + (M1^6 + (4*P1plus^2 + 1)*M1^4 - 2*M1^5 + 8*(2*P1plus^3 - P1plus^2)*M1^3 + 4*(4*P1plus^4 - 4*P1plus^3 + P1plus^2)*M1^2)*M2^2)*gamma^2 + (M1^6 + (4*P1plus^2 + 13)*M1^4 - 10*M1^5 + 16*(P1plus^3 + 3*P1plus^2 + 1)*M1^3 + 4*(4*P1plus^4 + 12*P1plus^3 - 3*P1plus^2 + 4*P1plus - 8)*M1^2 + 8*(4*P1plus^4 - 5*P1plus^2 - 2*P1plus + 1)*M1 + 4)*M2^2 + 4*(2*(P1plus^2 + 3*P1plus + 2)*M1^4 - M1^5 + (8*P1plus^3 + 24*P1plus^2 + 2*P1plus - 3)*M1^3 + 2*(4*P1plus^4 + 12*P1plus^3 + P1plus^2 - 6*P1plus - 1)*M1^2 + 2*(8*P1plus^4 - 10*P1plus^2 + 2*P1plus + 1)*M1)*M2 - 2*(((2*P1plus^2 + 6*P1plus + 1)*M1^4 + (8*P1plus^3 + 17*P1plus^2 - 2*P1plus - 2)*M1^3 + (8*P1plus^4 + 16*P1plus^3 - 10*P1plus + 1)*M1^2 + 3*(4*P1plus^4 - 5*P1plus^2 + 2*P1plus)*M1)*M2^6 + ((3*P1plus^2 + 12*P1plus - 2)*M1^4 + 2*M1^5 + 2*(6*P1plus^3 + 11*P1plus^2 - 2*P1plus - 2)*M1^3 + (12*P1plus^4 + 20*P1plus^3 + 3*P1plus^2 - 20*P1plus + 6)*M1^2 + 2*(8*P1plus^4 - 10*P1plus^2 + 6*P1plus - 1)*M1)*M2^5 + (M1^6 - 2*(3*P1plus^2 + 4*P1plus + 5)*M1^4 + 2*M1^5 - 2*(12*P1plus^3 + 22*P1plus^2 - 2*P1plus - 3)*M1^3 - (24*P1plus^4 + 40*P1plus^3 - 6*P1plus^2 - 12*P1plus - 5)*M1^2 - 4*(8*P1plus^4 - 10*P1plus^2 + 2*P1plus + 1)*M1)*M2^4 + 2*(M1^6 - (4*P1plus^2 + 8*P1plus + 3)*M1^4 - 2*M1^5 - (16*P1plus^3 + 20*P1plus^2 - 7)*M1^3 - 2*(8*P1plus^4 + 8*P1plus^3 + 2*P1plus^2 - 7*P1plus + 1)*M1^2 - (16*P1plus^4 - 20*P1plus^2 + 6*P1plus + 1)*M1)*M2^3 + (M1^6 + (4*P1plus^2 + 5)*M1^4 - 6*M1^5 + 4*(4*P1plus^3 + 5*P1plus^2
[sage-support] writing an equation on several lines
I encounter a problem splitting and equation on several lines using the backslash. Splitting works for any line, except for symbolic expressions where the error message ' SyntaxError: invalid syntax' occurs. A little example. * the following lines work : f = x^2 \ + 1 print f * but those don't work : f(x) = x^2 + 1 print f Is there a special syntax to split symbolic functions ? Regards. -- 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 URL: http://www.sagemath.org
[sage-support] Re: Sage fails to solve a polynomial (2nd order) system. What am I doing wrong ?
As Sage fails to solve the non-linear (2nd order polynomial) systems am I interested in, I tried to force the substitution of variables in the system to obtain an answer. In the example given below, the system corresponds to : g1 = 0 g2 = 0 where the unknowns are P1m and P2p. The others variables, P1p, M1, M2 and gm (s=0) are considered as parameters. g1 and g2 being polynomials of P1m and P2p, here is what I do manually : 1° I compute the P1p roots -- 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 URL: http://www.sagemath.org
[sage-support] Re: Sage fails to solve a polynomial (2nd order) system. What am I doing wrong ?
As Sage fails to solve the non-linear (2nd order polynomial) systems am I interested in, I tried to force the substitution of variables in the system to obtain an answer. In the example given below, the system corresponds to : g1 = 0 g2 = 0 where the unknowns are P1m and P2p. The others variables, P1p, M1, M2 and gm (s=0) are considered as parameters. g1 and g2 being polynomials of P1m and P2p, here is what I do manually : 1° I compute the P2p (named P2p_root) root of g1. P2p_root thus depends on P1m. 2° I evaluate g2 with P2p = P2P_root. Now, g2(P2p=P2p_root) only depends on P1m (and parameters P1p, M1, M2 and gm). 3° I compute the P1m root of g2(P2p=P2P_root). 4° I finally evaluate P2p_root with the value obtained at step 3° for P1m. Il works well for the first order system. However, for the second order system the resolution fails during step 3. Indeed, the P1m root of g2(P2p=P2P_root) contains the variable P1m, which sounds absurd to me. I don't understand why the command 'solve(g2(P2p=P2p_root)==0,P1m)' returns a result that depends on P1m ! Can please anybody help me? I really need to get the solutions of this problem and it is driving me crazy ! Best regards. # ## My code # Pp = var('Pp') Pm = var('Pm') s = var('s') M = var('M') gm = var('gm') #P1m and P2p are the unknowns P1p = var('P1p') P1m = var('P1m') P2p = var('P2p') P2m = var('P2m') M1 = var('M1') M2 = var('M2') assume(P1p 0) assume(M1 0) assume(M2 0) # First order # --- print First order resolution print -- f1 = (1+1/M)*Pp + (1-1/M)*Pm - s f2 = ( (gm-1)*(1+M)*Pp + (gm-1)*(1-M)*Pm + s ) / (1+(gm-1)/2*M^2) g1 = f1(Pp=P1p,Pm=P1m,s=0,M=M1) - f1(Pp=P2p,Pm=0,s=0,M=M2) g2 = f2(Pp=P1p,Pm=P1m,s=0,M=M1) - f2(Pp=P2p,Pm=0,s=0,M=M2) P2p_root = solve(g1==0,P2p)[0].rhs() P1m_root = solve(g2(P2p=P2p_root)==0,P1m)[0].rhs() P2p_root = P2p_root(P1m=P1m_root) print P1m = , P1m_root.factor() print P2p = , P2p_root.factor() # Second order # print print Second order resolution print --- f1 = (1+1/M)*Pp + (1-1/M)*Pm - s + s^2/2 - ((gm-1)*M-2)/(2*M)*Pp^2\ - ((gm-1)*M+2)/(2*M)*Pm^2 - (gm-1)*Pm*Pp - (1+1/M)*Pp*s - (1-1/M)*Pm*s f2 = ( (gm-1)*(1+M)*Pp + (gm-1)*(1-M)*Pm + s + s^2/2 - 2*(gm-1)*Pp*Pm \ + (gm-1)*Pp*s + (gm-1)*Pm*s ) / (1+(gm-1)/2*M^2) g1 = f1(Pp=P1p,Pm=P1m,s=0,M=M1) - f1(Pp=P2p,Pm=0,s=0,M=M2) g2 = f2(Pp=P1p,Pm=P1m,s=0,M=M1) - f2(Pp=P2p,Pm=0,s=0,M=M2) P2p_root = solve(g1==0,P2p)[0].rhs() P1m_root = solve(g2(P2p=P2p_root)==0,P1m)[0].rhs() P2p_root = P2p_root(P1m=P1m_root) print P1m = , P1m_root.factor() print P2p = , P2p_root.factor() -- 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 URL: http://www.sagemath.org
[sage-support] Sage fails to solve a polynomial (2nd order) system. What am I doing wrong ?
Hello, I am new to Sage and I want to use it to solve non-linear systems, used to model physical phenomenons. I unfortunately met some problems trying to solve a non-linear system composed of 3 polynoms (2nd order) I first successfully solved the linear problem, but when I try with the non-linear, 2nd order system, Sage runs endlessly before finally stopping with a message error. I am using the Online version of Sage (http://www.sagenb.org). The code I wrote is pasted at the end of my message. Can anybody tell me why cannot Sage doesn't provide a solution for the non-linear system and what I am doing wrong ? I spent several days looking at my code to find any error and finding clues on the Internet, but did not find anything helpful. I finally tried using Maxima, but I observe the same behavior and no solution is given for the non-linear system. A solution nevertheless exists : I started simplifying the equations and got a 2nd order polynom over 1 variable only. Coefficients are nevertheless quite big and I want to use Sage to factorize the roots and provide general solutions. Any help would be greatly appreciated. Regards. # ## My code # Pp = var('Pp') Pm = var('Pm') s = var('s') M = var('M') gm = var('gm') #P1m, P2p and s2 are the unknowns P1p = var('P1p') P1m = var('P1m') P2p = var('P2p') P2m = var('P2m') s1 = var('s1') s2 = var('s2') M1 = var('M1') M2 = var('M2') assume(P1p 0) assume(s1 0) assume(s2 0) assume(M1 0) assume(M2 0) # First order # --- print First order resolution print -- f1 = (1+1/M)*Pp + (1-1/M)*Pm - s f2 = ( (gm-1)*(1+M)*Pp + (gm-1)*(1-M)*Pm + s ) / (1+(gm-1)/2*M^2) f3 = s roots = solve( [f1(Pp=P1p,Pm=P1m,s=0,M=M1) - f1(Pp=P2p,Pm=0,s=s2,M=M2) == 0, \ f2(Pp=P1p,Pm=P1m,s=0,M=M1) - f2(Pp=P2p,Pm=0,s=s2,M=M2) == 0, \ f3(Pp=P1p,Pm=P1m,s=0,M=M1) - f3(Pp=P2p,Pm=0,s=s2,M=M2) == 0], \ P1m,P2p,s2) print , roots[0][0].factor() print , roots[0][1].factor() # Second order # print print Second order resolution print --- f1 = (1+1/M)*Pp + (1-1/M)*Pm - s + s^2/2 - ((gm-1)*M-2)/(2*M)*Pp^2\ - ((gm-1)*M+2)/(2*M)*Pm^2 - (gm-1)*Pm*Pp - (1+1/M)*Pp*s - (1-1/M)*Pm*s f2 = ( (gm-1)*(1+M)*Pp + (gm-1)*(1-M)*Pm + s + s^2/2 - 2*(gm-1)*Pp*Pm \ + (gm-1)*Pp*s + (gm-1)*Pm*s ) / (1+(gm-1)/2*M^2) f3 = s roots = solve( [f1(Pp=P1p,Pm=P1m,s=0,M=M1) - f1(Pp=P2p,Pm=0,s=s2,M=M2) == 0, \ f2(Pp=P1p,Pm=P1m,s=0,M=M1) - f2(Pp=P2p,Pm=0,s=s2,M=M2) == 0, \ f3(Pp=P1p,Pm=P1m,s=0,M=M1) - f3(Pp=P2p,Pm=0,s=s2,M=M2) == 0], \ P1m,P2p,s2) print , roots[0][0].factor() print , roots[0][1].factor() -- 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 URL: http://www.sagemath.org