2020-06-15 16:43:00 -0500 received badge ● Good Answer (source) 2019-06-12 14:23:46 -0500 received badge ● Nice Answer (source) 2019-01-16 05:04:05 -0500 received badge ● Nice Answer (source) 2018-08-13 12:22:30 -0500 received badge ● Nice Answer (source) 2018-06-12 20:25:01 -0500 received badge ● Nice Answer (source) 2018-02-13 15:10:50 -0500 received badge ● Nice Answer (source) 2017-11-19 05:29:27 -0500 answered a question Substitution of subexpression What's about: http://sagecell.sagemath.org/?q=oynzya ? 2017-11-06 10:49:28 -0500 answered a question How can I get back an expression for free variables in solve function. Are you looking for something like this ? 2017-10-27 15:43:16 -0500 commented answer Can I import a graphic and add to it? You can resize an image. See PIL or PILLOW documentation. ... img2 = img2.resize(img.size) img3 = PIL.Image.blend(img,img2,alpha=0.7)  2017-10-27 01:37:21 -0500 answered a question Can I import a graphic and add to it? See an example using PIL here. Please note: The images 'test.png' and 'test2.png' have to match, (same size, aspect_ratio). 2017-10-09 05:19:26 -0500 answered a question piecewise function with variable within domains What's about a python function? def my_piecewise(x0,x1): if 0 < x0 < x1 < 1: return piecewise([((0,x0),0), ([x0,x1],1), ((x1,1),2)], var=x) my_piecewise(0.2,0.7).plot()  2017-10-06 16:10:10 -0500 answered a question Solving a system of equations -- small known number hinders the solution var('x,y,z,K') #K=4.48e-13 # use later for substitution xi=0.75 yi=0 zi=0 eq1 = K==y^2*z/x^2 eq2 = xi+yi==x+y eq3 = 2*xi+yi+2*zi==2*x+y+2*z # x , y dependent on z solns = solve([eq2,eq3],x,y) print solns # z dependent on K solns2 = solve(eq1.subs(solns),z) print solns2 print solns2.subs(K=4.48e-13) # using real solution solns3 = solve([eq2,eq3.subs(z == 0.0000397877574911779)],x,y) for s in solns3: print s.lhs() == s.rhs().n(30)  2017-09-20 04:40:48 -0500 answered a question connecting plots by lines My suggestion see http://sagecell.sagemath.org/?q=rmiwzc Put both plots together with suitable translation and axes. 2017-09-03 05:00:55 -0500 answered a question Get the nth term of an equation.rhs() sum var('term_0 term_1 term_2 term_3') equ0 = term_0 == term_1 + term_2 + term_3 # use the operands method of expressions print equ0.rhs().operands() # subtract third term (the last in the list of operands) print equ0.rhs() - equ0.rhs().operands()[-1] # or build expression from list of operands print sum(equ0.rhs().operands()[:2])  2017-08-19 09:46:42 -0500 answered a question Defining functions acting on matrix elements? sage: M = matrix(2,2,var('a b c d')) sage: M; M.parent(); M(a=5) [a b] [c d] Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring [5 b] [c d]  We can use substitution M(a=5) (looking similar to a function call). What happens if we try to use M as variable of a function? sage: M = matrix(2,2,var('a b c d')) sage: print M.parent(); print sage: f(M) = M.transpose()  The error message indicates that the type of M has changed. Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring Traceback (click to the left of this block for traceback) ... AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'transpose'  M is no longer a matrix over SR but a symbolic expression. sage: M.parent() Symbolic Ring  When defining a symbolic function with a variable M, this M becomes (implicitly) a member of SR overwriting the previous definition of M. After redefining M as matrix: sage: A = M[0,0] + M[1,1] sage: A; A(a=5,b=3,c=0,d=-2) a + d 3  2017-08-10 08:33:36 -0500 received badge ● Nice Answer (source) 2017-08-05 02:38:02 -0500 answered a question How to assume the sum of some variables is equal to a constant? var('t1', 't2', 't3', 'a', 'b') expr1 = ((t1 + t2 + t3 - 1)*a)/b equ = t1 + t2 + t3 == 1 expr1.subs(solve(equ,t1))  2017-07-29 07:43:35 -0500 commented answer how accelerate this simple program math.sqrt returns a numerical value, sage sqrt returns a symbolic expression. See an example: http://sagecell.sagemath.org/?q=bgdeqj Exact symbolic operations are much slower than numerical algorithms. Converting a symbolic expression to a numerical value takes additional time. 2017-07-28 04:08:50 -0500 answered a question how accelerate this simple program One bottleneck comes from working with the symbolic ring. The following code is some hundred times faster (may be still not fast enough ;-) ) import math def count_2017(bound=100000): cpt = 0 for n in range (1,bound): if int(RR(math.sqrt(n)).frac()*10000) == 2017: cpt += 1 return cpt  Update: Using cython makes the code another ten times faster, for example: fits_2017 = cython_lambda("double x", "bool(int(10000*(x-int(x))) == 2017)") f = cython_lambda("int n", "sqrt(n)") def count_2017(bound=100000): cpt = 0 for n in range(1,bound): if fits_2017(f(n)): cpt += 1 return cpt count_2017(10^7)  2017-07-27 08:56:50 -0500 received badge ● Good Answer (source) 2017-07-26 17:55:47 -0500 received badge ● Famous Question (source) 2017-07-21 18:02:08 -0500 answered a question Piecewise Symbolic Function with Conditional Statement A special solution using symbolic functions: var('t') k(t) = t*(2-sign(t-1)^2) f(x)=sin(x)/k(t) f(t=3).integrate(x, 0, 1)  2017-07-18 10:55:22 -0500 commented answer Submatrix of a given matrix by deleting some rows and columns(For my case 2 rows and columns). A live example with nested for loops: http://sagecell.sagemath.org/?q=dzgfjy 2017-06-28 10:58:32 -0500 answered a question Animate rotating polytope To get the rotation axis stay constant, add an enveloping circle making this invisible with opacity = 0. Further set aspect_ratio=(1,1,1) as an option of animate. r = 2 y_axis = [r*vector((0,-1,0)),r*vector((0,1,0))] var('alpha') C = parametric_plot((r*cos(alpha),0,r*sin(alpha)),(alpha,0,2*pi),opacity=0) n=19 t = (2*pi/n).n() M=matrix([[cos(t),0,sin(t)],[0,1,0],[-sin(t),0,cos(t)]]) p=polytopes.cube() vl = [v[:3] for v in p.vertices()] sf = [] #[p] for i in range(n): vl = [M*v for v in vl] sf.append(Polyhedron(vl).plot(color='green',opacity=0.5,frame=False)+ C + line(y_axis,color='gold',thickness=2)) s=animate(sf,aspect_ratio=(1,1,1)) s.gif(savefile="an.gif")  2017-06-26 08:03:03 -0500 answered a question about solve() 2 equations Answer to the second question: solve returns a list of solutions. So you get something like solve([equ1,[equ2]],k,C). You have to refer to an equation in the list: solve([k^3==4*C,equC],k,C)  2017-06-21 07:08:52 -0500 received badge ● Nice Answer (source) 2017-06-21 03:46:43 -0500 answered a question How to simplify 1-cos(u)^2. There are far more simplify methods. expr.simplify? gives a hint: See also: "simplify_full()", "simplify_trig()", "simplify_rational()", "simplify_rectform()", "simplify_factorial()", "simplify_log()", "simplify_real()", "simplify_hypergeometric()", "canonicalize_radical()" In this case simplify_trig will do the job. var('u') expr = 1-cos(u)^2 expr.simplify_trig()  2017-06-20 03:14:07 -0500 answered a question to_poly_solve problem? If solve can't find an explicit solution, you can use find_root or the sympy solver: var ('N,m,sec,a,t,c') T = (1.27 * 10^6) Fg = ((9.81*107000)) a = ((T-Fg)/107000) v = a*t P3 = plot(v, (t,0,11)) y = v.integral(t) P1 = plot(y, (t,0,12)) T1 = 1.27*e^(-(t-11)/2) * 10^6 Fg = 9.81*107000 a1 =(T1-Fg)/107000 v1 = a1.integral(t) v1 = v1 + 154.299065420560 P4 = plot(v1, (t,11,22)) y1 = v1.integral(t) - 1026.68224299065 P2 = plot (y1, (t,12,22)) P = P1 + P2 Impact = y1.find_root(21,22) #print Impact P5 = P3 + P4 show(P5) dy1 = diff(y1, t) #print dy1 print 'solve with maxima solver:', solve(v1,t) print 'solve with find_root:', v1.find_root(0,20) import sympy print 'solve with sympy solver:', sympy.solve(v1,t)  2017-06-12 04:38:27 -0500 answered a question Help with unstable code The error "list index out of range" occurs if solve returns an empty list. You can capture this exception with a try except statement:  try: C = circle((sol.rhs(),sol.rhs()),sol.rhs()) except: pass  2017-06-04 04:12:17 -0500 answered a question sage thinks a float is a string This works for me: print("all {4:{0}.{1}} good {2} eat {3}".format(2,6,"dogs","shoes",x))  2017-06-02 17:55:52 -0500 commented question a problem with variables in real domains I am afraid you are not wrong. If we set z = y + I then conjugate(z.subs(y=5)) gives the result -I + 5 in contradiction to conjugate(z).subs(y=5) which results to I + 5 2017-05-30 07:28:08 -0500 received badge ● Nice Answer (source) 2017-05-29 11:00:03 -0500 commented question Transparency option in streamline plot You can use PIL to blend two images with alpha option. See an example here 2017-05-28 02:33:39 -0500 commented answer Periodic function Sorry for my misunderstanding. I ignored the 'even' because the function you provided isn't even. The easiest way to build a periodic function is to start with a periodic function. The start interval depends on the function you use and therefore we may need axis transformations to get the desired result. One more suggestion: f(x) = abs(arccos(cos(x))-pi)  2017-05-27 01:49:40 -0500 received badge ● Nice Answer (source) 2017-05-26 15:39:21 -0500 commented answer Periodic function Thanks for the hint. I tried to improve my answer. 2017-05-26 14:35:58 -0500 answered a question What is the meaning of 3d graph? The function f returns z values. That's all. Do not confuse with implicit_plot3d. There you normally use an expression containing x, y and z. 2017-05-26 09:14:27 -0500 answered a question Periodic function EDITED f(t) = -t + pi # interval [0, pi] g(t) = 1/2*f(t*pi) # transformed to interval [-1, 1] # h = lambda x: 2*g(RR(x/pi).frac()) # including retransformation h = lambda x: (heaviside(x)-1)*pi + 2*g(RR(x/pi).frac()) plot(h,-3*pi,3*pi)  UPDATE 2 --- a symbolic function: f(x) = 1/2*(sign(sin(2*x))*arccos(cos(2*x-pi)) + pi) plot(f,-3*pi,3*pi,aspect_ratio=1)  2017-05-23 02:30:40 -0500 answered a question elliptic curves plot sage: C = EllipticCurve([0,0,0,-2,0]).plot(xmin=-4, xmax=4, ymin=-3, ymax=3) sage: print C Graphics object consisting of 2 graphics primitives  I suppose the legend label entry shows up twice because there are two graphics primitives. You can split the plot and set the legend_label option only once. sage: p= plot(EllipticCurve([0,0,0,-2,0]), gridlines='true', color=hue(0.2),xmin=-4, xmax=0, ymin=-3, ymax=3, legend_label='$y^2=x^3-2x$') sage: p+=plot(EllipticCurve([0,0,0,-2,0]), gridlines='true', color=hue(0.2),xmin=1, xmax=4, ymin=-3, ymax=3) sage: p.set_legend_options(shadow=False, loc=2) sage: show(p)  2017-05-02 18:38:37 -0500 answered a question simplifying an expression Knowing the outcome you can do: var('b f k') expr = 2*b*f^2 + f^2*k - 2*b*f- f^2 - 2*f*k + b+2*f+k - 1 (expr - b*f^2).factor() + b*f^2  2017-05-01 12:18:14 -0500 answered a question Problems with sage solve. eq = 20000 * 1.02^x + 200 * (1 - 1.02^x) / (1 - 1.02) == 30000 eq2 = solve(eq,x) solve(log(eq2).canonicalize_radical(),x)  2017-04-24 10:47:19 -0500 answered a question How to create a Matrix with real numbers? sage: Z = matrix(2,2) sage: print Z.parent()  Output: Full MatrixSpace of 2 by 2 dense matrices over Integer Ring  That means your matrix can contain only Integers. What you want is a matrix over the Symbolic Ring: sage: Z = matrix(SR,2,2) sage: print Z.parent() sage: Z[0,0] = sqrt(5) sage: print Z  Alternatively a matrix over a Real Field: sage: Z = matrix(RR,2,2) sage: print Z.parent() sage: Z[0,0] = sqrt(5) sage: print Z