2020-12-22 17:20:32 -0600 received badge ● Notable Question (source) 2020-12-22 17:20:32 -0600 received badge ● Popular Question (source) 2020-01-15 08:47:15 -0600 commented answer how to get y component of bezier control points? then you use sage to solve $E_0$ and $E_1$ for the control points with Sol=solve([E0, E1], [x_1, x_2, y_1, y_2])  then Sol returns: [x_1 == r8, x_2 == r7, y_1 == d0*r8 - d0*x_0 + y_0, y_2 == d1*r7 - d1*x_3 + y_3]  so what are these r7 and r8 values? and where am i suppoosed to input the equation for my polynomial? 2020-01-15 08:45:06 -0600 commented answer how to get y component of bezier control points? expression for cubic bezier curve: $Bz = \sum_{u=0}^{v} Bn(v,u,t)$ = ${(-(t - 1)^3x_0 + 3(t - 1)^2tx_1 - 3(t - 1)t^2x_2 + t^3x_3 )$, $(-(t - 1)^3y_0 + 3(t - 1)^2ty_1 - 3(t - 1)t^2y_2 + t^3y_3) }$. with Bz=sum(map(lambda u,v:u*v, [Bn(3,w,t) for w in (0..3)], LP))  the expression for its derivatives: $dBz = Bz'(t) =$ $-3(t - 1)^2x_0 + 3(t - 1)^2x_1 + 6(t - 1)tx_1 - 6(t - 1)tx_2 - 3t^2x_2 + 3t^2x_3$, and $-3(t - 1)^2y_0 + 3(t - 1)^2y_1 + 6(t - 1)ty_1 - 6(t - 1)ty_2 - 3t^2y_2 + 3t^2y_3$. with  dBz=Bz.diff(t)  you use these identities to create these equations: $dB_0 ... 2020-01-15 08:43:22 -0600 commented answer how to get y component of bezier control points? im trying to follow along with your code and im not sure where the input is supposed to be so i tried to read your code in english, let me express my understanding of what your suggesting and what im still confused by. so list an expression for the control points:$LP = [(x_0,y_0),(x_1,y_1),(x_2,y_2),(x_3,y_3)]$. with LP=[vector([var("x_{}".format(u), domain="real"), var("y_{}".format(u),domain="real")]) for u in (0..3)]  expression for bernstein basis polynomials:$Bn(p,j,t) = {p\choose j}*t^j * (1-t)^{p-j}$, t = [0,1]. with var("t") Bn(p,j,t)=binomial(p,j)*t^j*(1-t)^(p-j)  2020-01-10 20:37:34 -0600 commented answer how to get y component of bezier control points? thank you im studying your answer now 2020-01-09 17:41:01 -0600 commented question how to get y component of bezier control points? @eric_g i did not see that documentation before but i will go through it also, @Emmanuel Charpentier thanks for that, I will upload my script shortly so you can see more where I am at 2020-01-09 13:13:55 -0600 commented question how to get y component of bezier control points? @Emmanuel Charpentier if i were to substitute those coefficients into poly i would just get some point along that curve, but the coefficients that i solve for with bezierControlPoints() are not the parameters of cubic bezier, that is what t is, so this is where my confusion lies 2020-01-09 13:12:18 -0600 commented question how to get y component of bezier control points? @Emmanuel Charpentier: yes, this is the reverse of the typical bezier problem. what I am doing is taking hand drawn curves that I ultimately need rendered in a browser. this curves are polynomials of various order. So I am taking the curves parameterzing them, and the parameterized curves are then the argument for the above bezierControlPoints() method. i do realize that point P = (0, poly(0)) and that point P = (1, poly(1)). what the bezierControlPoints() method above does is set up a system of linear equations for various values of t, solving for the coefficients of the cubic bezier. and so my question is how do i take those results, those coefficients and convert them into coordinates of ordered pairs? 2020-01-08 21:36:39 -0600 asked a question how to get y component of bezier control points? or is there a utility in sage that returns the bezier control points of a curve given that curve? im writing a program that takes a curve in polynomial form and returns those control points, this is the part in question: def bezierControlPoints(poly): a = sage.var('a') b = sage.var('b') c = sage.var('c') d = sage.var('d') t = sage.var('t') bezier = ((1 - t) ** 3) * a + 3 * ((1 - t) ** 2) * t * \ b + 3 * ((1 - t) * (t ** 2)) * c + (t ** 3) * d eqn1 = poly.substitute(t=0) eqn2 = poly.substitute(t=.33) eqn3 = poly.substitute(t=.66) eqn4 = poly.substitute(t=1) cb1 = bezier.substitute(t=0) cb2 = bezier.substitute(t=.33) cb3 = bezier.substitute(t=.66) cb4 = bezier.substitute(t=1) solns = sage.solve([eqn1 == cb1, eqn2 == cb2, eqn3 == cb3, eqn4 == cb4], a, b, c, d, solution_dict=True) return [[s[a].n(30), s[b].n(30), s[c].n(30), s[d].n(30)] for s in solns]  but the control points are coordinates, and this returns single numbers like coefficients. for example f(x) = x^4 - 10*x^3 + 35*x^2 - 50*x + 24  returns [24.000000, 3.8069265, -4.2949254, -0.30555556] [-0.30555556, 0.85185185, 0.85185185, -0.30555556] [-0.30555556, -1.3680046, -1.2661527, 0.00000000]  so how do i finish processing these portions of the control points? background the parts of the program i have written that i didnt share take the polynomial of arbitrary order, break it up into simpler subcurves, parameterize those subcurves, and those parameterized subcurves are the arguements of the bezierControlPoints(), which is called iteratively depending on the order of the polynomial. 2020-01-02 22:43:44 -0600 commented answer can sage return a list of numbers from solve() instead of expressions? yet better: solns = sage.solve([eqn1 == cb1, eqn2 == cb2, eqn3 == cb3, eqn4 == cb4], a, b, c, d, solution_dict=True) return [[s[a].n(30), s[b].n(30), s[c].n(30), s[d].n(30)] for s in solns]  2020-01-02 22:27:52 -0600 commented answer can sage return a list of numbers from solve() instead of expressions? this is how, [(a.subs(w), b.subs(x), c.subs(y), d.subs(z)) for (w, x, y, z) in sage.solve(((eqn1 == cb1), (eqn2 == cb2), (eqn3 == cb3), (eqn4 == cb4)), (a, b, c, d))]  2020-01-02 22:02:15 -0600 commented answer can sage return a list of numbers from solve() instead of expressions? how would the above work for multivariate functions? ive tried [a.subs(w) for w b.subs(x) for x c.subs(y) for y d.subs(z) for z in sage.solve(((eqn1 == cb1), (eqn2 == cb2), (eqn3 == cb3), (eqn4 == cb4)), (a, b, c, d))]  and [a.subs(w), b.subs(x), c.subs(y), d.subs(z) for w, x, y, z in sage.solve(((eqn1 == cb1), (eqn2 == cb2), (eqn3 == cb3), (eqn4 == cb4)), (a, b, c, d))]  and neither are valid syntax 2019-12-29 00:02:07 -0600 asked a question can sage return a list of numbers from solve() instead of expressions? is there any builtin methods to have solve() return a list of numbers instead of the sequence of expressions that it does? which is to say solve(eqn, x) would return:$[x_1, x_2, ...,x_n]$instead of:$[x == x_1, x == x_2, ... , x == x_n]\$ or if there are not any built in functions recommended approaches? this is in a sage script im rating that at this point in the program is taking polynomials, computing their first and second derivatives, and adding the roots of those derivatives to a list, which needs to be iterable. if there does not exist some sage method or options for this, i believe i would need to revert to regex, which feels like im doing something wrong if thats what im having to do here 2019-12-23 12:34:15 -0600 received badge ● Commentator 2019-12-23 12:34:15 -0600 commented answer can you programmatically define a [mathematical] function? i agree, theres polyfit from numpy i believe, which does interpolation to find equation of best fit but thats as close as ive found 2019-12-19 07:38:55 -0600 commented answer can you programmatically define a [mathematical] function? when used in a script it looks like: x = sage.var('x') polynomial = poly_from_coeffs(solution, x) print polynomial, '\n' print polynomial.diff(2), '\n'  i did not realize the summation function could be used without indices. thank you for your answer works very well 2019-12-19 07:36:17 -0600 commented answer can you programmatically define a [mathematical] function? thank you for your additional answer, like the one above i did not know you could use the summation function without indices. 2019-12-18 15:33:25 -0600 asked a question can you programmatically define a [mathematical] function? I want to take an array of coefficients and turn that into a function, a math function not a python function. for example take [2, 0, 2, 7]  and turn this into $$f(x) = 2x^3 + 2x + 7$$ something like def createSym(coefficients, degree, x): symbolicEqn = '' for i in poly: symbolicEqn += ' + ', (x**deg)*i deg -= 1 return symbolicEqn pass  then call my definition in the script like x = var('x') coeffArray = [2, 0, 2, 7] degree = 3 polynomialEqn = createSym(coeffArray, degree, x)  But symbolicEqn is just a string and not an expression. Is there a sage/python way to do this? 2019-12-07 20:24:10 -0600 commented answer can't import sage into python i did yes, even moved the files in question to a new folder. seems like pylint is having trouble identifying sage as a dependency of the script maybe? 2019-12-07 20:01:56 -0600 commented answer can't import sage into python that worked, thank you very much. don't know if i should be surprised with that or not, not very familiar with python behavior. and so would you be able to comment why pylint is throwing so many errors? No name 'all' in module 'sage' Unable to import 'sage.all' Undefined variable 'factor' Undefined variable 'sage_eval'  2019-12-06 21:59:59 -0600 asked a question can't import sage into python trying to write a python/sage script and in starting i am following the example  #!/usr/bin/env sage import sys from sage.all import * if len(sys.argv) != 2: print("Usage: %s " % sys.argv) print("Outputs the prime factorization of n.") sys.exit(1) print(factor(sage_eval(sys.argv)))  from this sage docs link and i continue to get the variety of erros: ModuleNotFoundError: No module named 'sage.all'; 'sage' is not a package ImportError: No module named all and variations thereof. sage runs from any directory just by typing sage and enter, so i dont believe its a path issue. ive also tried passing the -python argument to the shebang at the top of the script. i have tried to execute the script using: sage -python sage.py ./sage.py i have also tried saving the file with a .sage extension and invoking the script also as above, all of and any combinations complain of the same inability to resolve the module importing of sage into the script. i know there are a number of similar questions on this site related to that error, but they most all seemed to also have problems invoking sage successfully from the cl with just typing sage