Ask Your Question

tmonteil's profile - activity

2019-01-17 06:10:57 -0600 answered a question How to compute the number of nods in each orbit of a graph?

If you define o as the orbits:

sage: o = group.orbits()

you can get the list of number of vertices in each orbit as follows:

sage: [len(i) for i in o]

If you prefer a vector:

sage: vector([len(i) for i in o])
2019-01-15 08:28:25 -0600 commented question sage 8.5 windows jupyter can't work

Does it work when launch the notebook by clicking to the "jupyter noebook" icon, not typing sage -n from the shell ?

2019-01-14 07:26:54 -0600 received badge  Good Answer (source)
2019-01-11 07:23:51 -0600 commented answer Combine plots with built-in Maxima, trajectory in Sage available?

What feature of maxima is missing in Sage ? The only code from maxima that i see is the plotting, so i just explained how to move that part in Sage.

2019-01-11 04:17:22 -0600 answered a question Plot of linear programming restrictions 2d, 3d

You should give more deatils (e.g. your linear proogram, what do you want to restrict, etc). Without more informations, given a linear program p of dimension 2 or 3, you can get its polyhedron as follows:

sage: p.polyhedron()

that you can plot as follows:

sage: p.polyhedron().plot()
2019-01-10 18:38:20 -0600 received badge  Nice Answer (source)
2019-01-10 18:34:48 -0600 answered a question can we use BFS and DFS algorithm in sagemath?

You can do BFS and DFS as follows:

sage: G = graphs.PetersenGraph()
sage: G.plot()
sage: list(G.breadth_first_search(start=3))
[3, 2, 4, 8, 1, 7, 0, 9, 5, 6]
sage: list(G.depth_first_search(start=3))
[3, 8, 6, 9, 7, 5, 0, 4, 1, 2]

What you get is the ordered list of vertices visited in both searches, starting from vertex 3.

Regarding coloring, i am not sure about your exact question. If you want to provide colors to the vertices to show the order of visit, you can try somthing like:

sage: G.plot(vertex_colors={rainbow(40)[i]:[v] for i,v in enumerate(G.breadth_first_search(start=3))})

With more striking example:

sage: G = graphs.Grid2dGraph(10,10)
sage: G.plot()
sage: G.plot(vertex_colors={rainbow(500)[i]:[v] for i,v in enumerate(G.breadth_first_search(start=(0,0)))})
sage: sage: G.plot(vertex_colors={rainbow(500)[i]:[v] for i,v in enumerate(G.depth_first_search(start=(0,0)))})
2019-01-10 18:03:21 -0600 commented question Expected value of random variables

Is it homework ? Before trying to solve such a problem with Sage, how would you have solved it by hand ?

2019-01-10 18:00:43 -0600 answered a question Combine plots with built-in Maxima, trajectory in Sage available?

You can add plots in Sage, so in your case:

sage: plot_slope_field(4*y/x+x*sqrt(y),(x,0,4),(y,0,10),headaxislength=3,headlength=3, color='red') + plot(1/4*x^4*(log(x)+2)^2,0,4, ymax=10, color='blue')
2019-01-10 12:57:16 -0600 commented question How to solve this system of equation in sage?

k is supposed to be fixed ?

2019-01-10 10:29:39 -0600 commented answer How to format posts on this forum?

Once you have 1000 karma points, you will be able to do that :)

2019-01-10 10:28:44 -0600 answered a question Is it possible to import machine learning libraries in Sage?

You have to install the Python packages in the Sage virtual environement. For this, you have to open a terminal (assuming you are using GNU/Linux) and type:

sage --pip install tensorflow

And then, from Sage:

sage: import tensorflow
2019-01-09 14:06:49 -0600 received badge  Nice Answer (source)
2019-01-09 14:00:02 -0600 received badge  Nice Answer (source)
2019-01-08 16:15:02 -0600 answered a question Quadratic equation with complex coefficients

The solutions are correct but they are not fully simplified.

sage: f= x^2 - (1 + I)*x + 6 + 3*I
sage: solve(f==0,x)
[x == -1/2*sqrt(-10*I - 24) + 1/2*I + 1/2, x == 1/2*sqrt(-10*I - 24) + 1/2*I + 1/2]

For each solution, you can simplify its right-hand-side as follows:

sage: [s.rhs().full_simplify() for s in solve(f==0,x)]
[3*I, -2*I + 1]
2019-01-08 16:11:26 -0600 edited question Quadratic equation with complex coefficients

How can I solve x^2 - (1 + I)*x + 6 + 3*I == 0 to get answers z = 3*I and z = 1 - 2*I ? When I enter

solve(x^2 - (1 + I)*x + 6 + 3*I == 0, x)

I get

[x == -1/2*sqrt(-10*I - 24) + 1/2*I + 1/2, x == 1/2*sqrt(-10*I - 24) + 1/2*I + 1/2]
2019-01-08 16:10:04 -0600 answered a question How to format posts on this forum?

Not exactly Markdown, but close to it, you can discover the syntax by editing a post and clicking on the icons on top of the edit section (e.g. B, I, planet, ", 101010, picture,...).

For example bild is obtained with **, italic with *, and so on.

Regarding formatting Sage, you can have a monospaced code either with the button 101010, or by adding 4 spaces at the beginning of very code line.

I edited your other question, you can check the markup by editing it.

2019-01-08 08:01:09 -0600 received badge  Nice Answer (source)
2019-01-08 06:20:13 -0600 commented question Can't display figures

Could you please give us some informations so that someone can try to reproduce your problem:

  • which version of Sage did you use ?
  • which OS ?
  • did you install Sage from the binaries, and which ones ?
  • did you compile Sage yourself ?
2019-01-08 04:33:01 -0600 commented answer Generic Symbolic function as input in actual funciton

%time is not a function, it is a "ipython magic", you can use it within the command line or a notebook.

2019-01-07 12:43:32 -0600 answered a question Any way to make Sage display large matrices all in 1 line?

I do not know about cocalc, but on sagenb and jupyter you can simply do:

show(A)

Or, if you want to see dots on the nonzero indices:

plot(A)

Or, if you want to see the matrix in a pdf file:

view(A)
2019-01-07 12:32:29 -0600 answered a question Generic Symbolic function as input in actual funciton

Here are some remarks:

First, remove any time-related lines and variables from your function. You can later time it with:

sage: %time Newton_Raphson(f, 0.2)

or even:

sage: %timeit Newton_Raphson(f, 0.2)

so that you get a race between many executions.

Then, you might want to run something like:

sage: %time Newton_Raphson(f,1)

and see that your code is lagging.

To understand what happens, let me suggest to add some debug information just after the while statement:

print start

As you can see, the value of the start real number is expressed as a huge symbolic expression involving exponentials. So you can imagine that handling such expression and testing inequalities with them is very slow (and more and more slow since the size of the expression increases a lot at each iteration).

Since you the Newton Raphson will never reach the zero of the function exactly, wht you are looking for is an approximation, so you don not care to have a long expression for such a point whose only virtue is to be close to the zero. So, yo may want a numerical approximation. For this, you can transform each of foo, dfoo and ddfoo as functions tranforming floating-point numbers into floating-point numbers, which you can do by using the fast_float function.

So just after defining dfoo and ddfoo, it suffice to add the lines:

foo = fast_float(foo)  
dfoo = fast_float(dfoo)                        
ddfoo = fast_float(ddfoo)

Of course, you should not re-define foo before defining dfoo as Sage is not able to compute the derivative of a such numerical function, you prefer exact symbolic computations for such a computation of derivatives.

With such improvement, you can now get:

sage: %time Newton_Raphson(f,0)
CPU times: user 4 ms, sys: 0 ns, total: 4 ms
Wall time: 3.25 ms
(0.8571428346650166, 7, 0.0)

Hmm, apparently the error is zero. The reason is that in your code there is:

start = NR
error = (NR - start)

so of course the error is zero ! perhaps should you permute those two lines.

2019-01-06 10:39:47 -0600 commented question a.N(3) DID WORK past now only N(a,3) ???

Could you please tell u show did you define a ?

2019-01-06 08:15:37 -0600 answered a question Working with sums/products of lists

I am not sure to understand your request, but if it is OK to work with n fixed, does the following help you ?

sage: n = 3
....: var('a','b')
....: assume(a>0,b>0)
....: X = [SR.var('X_{}'.format(i)) for i in range(n)]
....: L = prod(a*b*X[i]^(a-1)*(1-X[i]^a)^(b-1) for i in range(n))

sage: L
X_0^(a - 1)*(-X_0^a + 1)^(b - 1)*X_1^(a - 1)*(-X_1^a + 1)^(b - 1)*X_2^(a - 1)*(-X_2^a + 1)^(b - 1)*a^3*b^3

sage: L.diff(a)
-X_0^(a - 1)*X_0^a*(-X_0^a + 1)^(b - 2)*X_1^(a - 1)*(-X_1^a + 1)^(b - 1)*X_2^(a - 1)*(-X_2^a + 1)^(b - 1)*a^3*(b - 1)*b^3*log(X_0) - X_0^(a - 1)*(-X_0^a + 1)^(b - 1)*X_1^(a - 1)*X_1^a*(-X_1^a + 1)^(b - 2)*X_2^(a - 1)*(-X_2^a + 1)^(b - 1)*a^3*(b - 1)*b^3*log(X_1) - X_0^(a - 1)*(-X_0^a + 1)^(b - 1)*X_1^(a - 1)*(-X_1^a + 1)^(b - 1)*X_2^(a - 1)*X_2^a*(-X_2^a + 1)^(b - 2)*a^3*(b - 1)*b^3*log(X_2) + X_0^(a - 1)*(-X_0^a + 1)^(b - 1)*X_1^(a - 1)*(-X_1^a + 1)^(b - 1)*X_2^(a - 1)*(-X_2^a + 1)^(b - 1)*a^3*b^3*log(X_0) + X_0^(a - 1)*(-X_0^a + 1)^(b - 1)*X_1^(a - 1)*(-X_1^a + 1)^(b - 1)*X_2^(a - 1)*(-X_2^a + 1)^(b - 1)*a^3*b^3*log(X_1) + X_0^(a - 1)*(-X_0^a + 1)^(b - 1)*X_1^(a - 1)*(-X_1^a + 1)^(b - 1)*X_2^(a - 1)*(-X_2^a + 1)^(b - 1)*a^3*b^3*log(X_2) + 3*X_0^(a - 1)*(-X_0^a + 1)^(b - 1)*X_1^(a - 1)*(-X_1^a + 1)^(b - 1)*X_2^(a - 1)*(-X_2^a + 1)^(b - 1)*a^2*b^3
2019-01-06 06:37:39 -0600 commented question count in numbers x**x

Could you plase make your question more explicit ? Dou you want to count the number of solutions to this equation ? On which domain ?

2019-01-05 07:22:30 -0600 received badge  Nice Answer (source)
2019-01-04 23:05:27 -0600 received badge  Nice Answer (source)
2019-01-04 05:00:58 -0600 answered a question Deformed 3d shapes

You should define your deformed cube as a polyhedron, see the inline doc at:

sage: Polyhedron?

See also:

2019-01-03 13:47:17 -0600 received badge  Good Answer (source)
2019-01-03 12:15:25 -0600 commented question .coefficients output

Could you please provide your current code (in particular the differential equation) ?

2019-01-03 12:12:51 -0600 commented question Quaternion * integer

Culd you please provide your implementation of the quaternions ?

2019-01-03 10:28:45 -0600 received badge  Good Answer (source)
2019-01-03 09:29:11 -0600 received badge  Nice Answer (source)
2019-01-03 08:53:43 -0600 commented answer 3dplot molecule drawing

You can use text3d and add it to the previous plot:

sage: text3d("plop",(1,2,0))
2019-01-03 08:50:42 -0600 answered a question plot parametric curve from symbolic expressions

There is a dedicated function for parametric plots:

sage: parametric_plot(x1sol, (ts, 0, 1))
2019-01-03 07:52:33 -0600 received badge  Good Answer (source)
2019-01-03 05:22:22 -0600 received badge  Nice Answer (source)
2019-01-02 16:18:26 -0600 answered a question permutation with repetition count

You can use product provided by the itertools Python module:

sage: list(product([0,1,2], repeat=2))
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
2019-01-02 16:15:56 -0600 commented question I=∫e^x((sin−1x)−3x(3+2x^2)/(1−x^2)^7/2)dx

Sure, but what is your question ?

2019-01-02 16:14:49 -0600 answered a question 3dplot molecule drawing

You can draw a sphere as follows:

sage: sphere((0,0,0), size=1, color='red')

You can add plots together:

sage: sphere((0,0,0), size=1, color='red') + sphere((2,0,0), size=1.5, color='green')

You can ensure that all the axes are on the same scale, with aspect_ratio=1:

sage: sphere((0,0,0), size=1, color='red') + sphere((2,0,0), size=1.5, color='green', aspect_ratio=1)