Ask Your Question

ndomes's profile - activity

2021-04-03 10:55:36 +0200 received badge  Nice Answer (source)
2021-01-19 17:32:29 +0200 received badge  Nice Answer (source)
2021-01-14 22:15:49 +0200 received badge  Good Answer (source)
2021-01-11 15:44:22 +0200 received badge  Notable Question (source)
2020-06-15 23:43:00 +0200 received badge  Good Answer (source)
2019-06-12 21:23:46 +0200 received badge  Nice Answer (source)
2019-01-16 12:04:05 +0200 received badge  Nice Answer (source)
2018-08-13 19:22:30 +0200 received badge  Nice Answer (source)
2018-06-13 03:25:01 +0200 received badge  Nice Answer (source)
2018-02-13 22:10:50 +0200 received badge  Nice Answer (source)
2017-11-19 12:29:27 +0200 answered a question Substitution of subexpression
2017-11-06 17:49:28 +0200 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 22:43:16 +0200 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 08:37:21 +0200 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 12:19:26 +0200 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)

2017-10-06 23:10:10 +0200 answered a question Solving a system of equations -- small known number hinders the solution
#K=4.48e-13   # use later for substitution
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[2].subs(K=4.48e-13)   # using real solution
solns3 = solve([eq2,eq3.subs(z == 0.0000397877574911779)],x,y)
for s in solns3[0]: print s.lhs() == s.rhs().n(30)
2017-09-20 11:40:48 +0200 answered a question connecting plots by lines

My suggestion see

Put both plots together with suitable translation and axes.

2017-09-03 12:00:55 +0200 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 16:46:42 +0200 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
2017-08-10 15:33:36 +0200 received badge  Nice Answer (source)
2017-08-05 09:38:02 +0200 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
2017-07-29 14:43:35 +0200 commented answer how accelerate this simple program

math.sqrt returns a numerical value, sage sqrt returns a symbolic expression.

See an example:

Exact symbolic operations are much slower than numerical algorithms. Converting a symbolic expression to a numerical value takes additional time.

2017-07-28 11:08:50 +0200 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

2017-07-27 15:56:50 +0200 received badge  Good Answer (source)
2017-07-27 00:55:47 +0200 received badge  Famous Question (source)
2017-07-22 01:02:08 +0200 answered a question Piecewise Symbolic Function with Conditional Statement

A special solution using symbolic functions:

k(t) = t*(2-sign(t-1)^2)
f(t=3).integrate(x, 0, 1)
2017-07-18 17:55:22 +0200 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:

2017-06-28 17:58:32 +0200 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))]

C = parametric_plot((r*cos(alpha),0,r*sin(alpha)),(alpha,0,2*pi),opacity=0)

t = (2*pi/n).n()
vl = [v[:3] for v in p.vertices()]
sf = [] #[p]
for i in range(n):
    vl = [M*v for v in vl]
              C + line(y_axis,color='gold',thickness=2))
2017-06-26 15:03:03 +0200 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:

2017-06-21 14:08:52 +0200 received badge  Nice Answer (source)
2017-06-21 10:46:43 +0200 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.

expr = 1-cos(u)^2
2017-06-20 10:14:07 +0200 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

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 11:38:27 +0200 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:

        C = circle((sol[1][0].rhs(),sol[1][1].rhs()),sol[1][2].rhs())    
2017-06-04 11:12:17 +0200 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-03 00:55:52 +0200 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 14:28:08 +0200 received badge  Nice Answer (source)
2017-05-29 18:00:03 +0200 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 09:33:39 +0200 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 08:49:40 +0200 received badge  Nice Answer (source)
2017-05-26 22:39:21 +0200 commented answer Periodic function

Thanks for the hint. I tried to improve my answer.

2017-05-26 21:35:58 +0200 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 16:14:27 +0200 answered a question Periodic function


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())

UPDATE 2 --- a symbolic function:

f(x) = 1/2*(sign(sin(2*x))*arccos(cos(2*x-pi)) + pi)
2017-05-23 09:30:40 +0200 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)