Ask Your Question

dazedANDconfused's profile - activity

2019-02-03 10:06:26 -0600 commented question Piecewise in SageTeX

Can you post your LaTeX code? I have no trouble plotting the piecewise function you used with sagetex. Maybe I don't understand what you are attempting. Also, are you using Cocalc off the internet or is this compiled using Sage from your computer? If Sage from your computer, what version of Sage?

2018-11-30 02:41:05 -0600 received badge  Nice Answer (source)
2018-11-29 12:09:16 -0600 commented answer log base 2 in sagemath

Nice! I wasn't aware of that book.

2018-11-29 11:52:50 -0600 answered a question log base 2 in sagemath

You've done it correctly and SAGE gives you the exact answer. If you try log(8,2) you'll get 3 because that's the exact answer and no logs are required. To force a numerical answer try, for example log(1000,2).n(digits=9) to get an approximate answer of 9.96578429. You can check if that's close by typing 2^9.96578429 to get 1000.00000369996. Want a closer answer? Change to digits=12 and repeat. Same thing with other functions such as sqrt(2).n(digits=4)

Alternatively, the documentation gives n(log(1000,2)) which gives you the approximation 9.96578428466209 with less key strokes. You can find the log function documentation here

2018-11-23 14:53:33 -0600 commented answer Is it possible to access Sage with an android tablet?

I tried but your instructions haven't working for me. I was, for example, pushed to install ConnectBot and then didn't seem to configure it correctly. So I could never get to CLI prompt. I'm stuck in ConnectBot with an error about "the authenticity of 'localhost' can't be established".

2018-11-22 09:18:01 -0600 commented question Is it possible to access Sage with an android tablet?

I've had problems with using the Sage app but there is a Sage Cell Server on the internet. So any tablet can access Sage. I don't find them convenient for anything but a couple of lines of code, given the lack of a real keyboard.

2018-11-07 20:06:15 -0600 commented question drawing the corners for the inner parallelogram(solved)

I'm having trouble understanding the question. What is a angle circle? From your code, I think you might mean arc. Your commented line is drawing the arc for an ellipse. The documentation is here and at the bottom of the page indicates you would want something like g+=arc((0,0), 1, sector=(pi/4,3*pi/4)) but I'm not sure where you want it to start and stop. What does "and add the alpha character into it" mean?

2018-11-07 10:18:34 -0600 commented question finding general term of a sequence

There is no "the nth term" for a sequence like you've given with ... . For example: 1,2,3,.... could be the sequence f(n)=n or it could be f(n)=n^3-6n^2+12n-6. There are actually an infinite number of formulas that could work here.

2018-10-26 21:45:33 -0600 commented question Need help with plotting

This sounds like homework where there's a misunderstanding as to what you're supposed to do. Try: t = var('t') parametric_plot((cos(t)+cos(2t), sin(t) + sin(3t)), (t, 0, 2*pi), color=hue(0.6)) to see the parametric curve formed by your equations above. You can't form a line without a specific value of t to get the second point.

2018-10-26 11:41:45 -0600 commented question Indefinite integral is incorrect

Using integral(sqrt(1+cos(x)**2), x).full_simplify() as suggested still results in an answer which is incorrect, doesn't it? This is a nonelementary integral. See here or here

2018-10-21 11:23:05 -0600 answered a question next prime number

Here is a possible implementation of what you are trying to accomplish using a Sage interact and the prime_range function that slelievre mentions in their answer:

def FindPrimes(start=1, end=100):
    PrimeList = prime_range(start, end)
    print "There are ", len(PrimeList), " primes between ", start, " and ", end
    print "The next prime after start is ", next_prime(start)
    print "The primes between ", start, " and ", end, " are: "
    for i in range(0,len(PrimeList)):
        print PrimeList[i]

Copy and paste the code into a Sage Cell Server. Press Evaluate. To change the start value the user can go to the input cell, type, for example, 35, and press enter. The Sage Interact then updates the results.

2018-10-19 10:52:09 -0600 commented question drawing the function y = |log x|

Although most people learn the logarithm has domain positive reals and range all reals the logarithm, like other functions such as e^x, gets extended to the complex number system. Type: log? on the command line for Sage to see further down: "The log function works for negative numbers, complex numbers, and symbolic numbers too, picking the branch with angle between -pi and pi". Since the absolute value of a complex number is just its distance from the origin Sage has done everything correctly.

2018-10-02 10:35:17 -0600 commented question Help in generating Ulam numbers

This isn't a Sage related issue; it's a Python coding question. You can find working Python code for this problem on the internet with a simple internet search.

2018-09-24 20:05:51 -0600 answered a question How to plot a set of points?

The documentation for Sage plotting in 2 dimensions is here. From your description, I think you are talking about region_plot(). Here's an example:

x,y = var('x,y')
region_plot([x^2 + y < 1, x < y], (x,-2,2), (y,-2,2))

The region plotted consists of the points satisfying both inequalities (intersection), where x is in the interval [-2,2] and y is in the interval [-2,2].

2018-04-12 08:08:12 -0600 received badge  Famous Question (source)
2018-02-02 14:23:03 -0600 commented answer How to save graphics into an image in sagemath online?

Not clear what you mean when you talk about "changed in strange ways". What's the strange behavior you are talking about? The option to zoom/rotate is for 3d images. Try typing G = dodecahedron(color='darkseagreen',opacity=0.2) After pressing enter, right click on the image. It will give you the options of zooming and rotating. When the image is how you want right click and export to a jpg file or some other image file. I've been able to get high quality images (such as fractals) by saving the image to pdf. You can also force the data through LaTeX using the sagetex package along with tikz/pgfplots to produce high quality illustrations.

2018-02-01 09:25:31 -0600 commented question Sagetex doesn't compile tex file with figures

This runs for me as well. Sometimes problems can disappear if you delete all but the .tex file and then recompile.

2017-12-04 10:59:24 -0600 received badge  Popular Question (source)
2017-12-04 10:59:24 -0600 received badge  Notable Question (source)
2017-08-27 07:36:51 -0600 received badge  Notable Question (source)
2017-05-18 10:38:15 -0600 answered a question Sage syntax highligh for LaTeX

Dr William Stein, one of the developers of Sage, has a LaTeX source file online where he uses Sage code. The location of the file and basic instructions are found on the TeX StackExchange site, here.

2017-03-21 12:03:40 -0600 received badge  Popular Question (source)
2016-03-03 09:06:39 -0600 asked a question Changing vertex labels on a randomly generated graph

I know that if I want to create a graph on 4 vertices with vertex labels 1,2,3,4 then I can define my graph like this: G = Graph({0: [1, 3], 1: [2, 3,4], 2: [1,4], 3: [], 4: []})

and then when I print in LaTeX using sagetex the labels show up as 1,2,3,4 but when I try to create a graph randomly graphs.RandomGNM(4,5)).show(figsize=[4,4], graph_border=True) the vertex labels are 0,1,2,3. How do I change the default vertex labels of a randomly created graph?

2016-01-28 09:19:18 -0600 commented question Integer result for fraction

In working with Sage you have to know if you are dealing with a Sage integer or Python integer. They behave differently. Use srange as indicated in answer below. See also, this similar post

2015-08-05 21:54:13 -0600 answered a question How to plot a parabola (conic): y²=4ax

You could try plotting it as two functions but implicit_plot is the natural choice. The documentation is here. This simple code illustrates how it could be done, given a specific value of a:

x, y = var('x,y')
implicit_plot(y^2==4*a*x, (x,-2,10), (y,-8,8))

Note the double equal signs. You can run the code in any Sage Cell Server, such as here, to check the result. Plotting it as two functions:

A = plot(2*sqrt(a*x), (x, -2, 10))
B = plot(-2*sqrt(a*x), (x, -2, 10))

and with a little complaining Sage plots over values that avoids problems with the domain.

2015-07-03 13:12:29 -0600 answered a question X and Y values of plot points using implicit_plot

I noticed Sage plot inner structure posted on the sidebar and after some time puzzling through the details came up with the following code to work off of:

x,y = var('x,y')
gridDim = 300
xmin = -2
xmax = 2
deltax = (xmax-xmin)/(gridDim-1)
ymin = -2
ymax = 2
deltay = (ymax-ymin)/(gridDim-1)
xvals = []
yvals = []
P=implicit_plot(f, (x,xmin,xmax), (y,ymin,ymax),plot_points=gridDim)
C = P._objects[0]
for i in range(0,gridDim):
    for j in range(0,gridDim):
        if abs(C.xy_data_array[i][j])<.02:
            xvals += [xmin+j*deltax]
            yvals += [ymin+i*deltay]

To look at the points on the curve add these 2 lines:

for i in range(0,len(xvals)):
    print "(%f,%f),"%(xvals[i],yvals[i])

As the link showed, the default number of points is a grid of 150 by 150. I found it necessary to have a bigger grid size and the plot_points=200 makes a 200 by 200 grid of 40,000 points. The comment "Then you get the points by looking at sign changes, or values close to zero." refers to the fact that most of those points aren't plotted. The actual points that end up getting plotted from the grid are just those where f(x,y) is close to 0--I chose abs(C.xy_data_array[i][j])<.02 and have been getting expected results.

2015-06-14 14:38:57 -0600 commented answer No able to get the results from the last segment

I ran it in the SageCellServer and Sage has a lot to say: "RuntimeWarning: tp_compare didn't return -1 or -2 for exception" with a page of code ending in "TypeError: double_from_pyobj failed in converting argument f of call-back function cb_calcfc_in__cobyla__user__routines to C double". Above my head but and too much going on but perhaps running in Sage Cell Server will help rather than old Sage5.6. I'm not sure why there's no error for madan26.

2015-06-06 17:01:12 -0600 commented answer Student worksheet to embed in website using sage

That's an interesting option I'd never heard of. Will have to explore more. Thanks!

2015-06-06 14:55:15 -0600 received badge  Nice Answer (source)
2015-06-06 13:35:37 -0600 commented answer Student worksheet to embed in website using sage

I've struggled with this problem a bit. Given your preference (which is actually the route I'm on) I think it's just about creating LaTeX documents using sagetex package to access Sage's math capabilities. Creating the problems takes a lot of time because of the debugging aspect and for unexpected times when Sage takes your input or output and represents it in a way you don't want. (try having Sage do the quotient rule). Depending on the problem, randomly created problems can be extremely complicated and forcing Sage to show what you want can be extremely time consuming. One use of Sage was to create random problems and then pick out the "best" ones for a quiz/test. You can find lots of examples here to guide you.

2015-06-05 18:53:15 -0600 answered a question Student worksheet to embed in website using sage

Actually, I think you do want the Sage Cell Server. For example, copy this simple example into a Sage Cell Server:

def Midpoint(ShowSolution=checkbox(default=True, label='Check to show solution')):
    html('Find the midpoint of $(%s,%s)$ and $(%s,%s)$.'% (x1,y1,x2,y2))
    if ShowSolution==True:
        if (x1+x2)/2 in ZZ or(x1+x2)/2 in ZZ:

You can probably see the LaTeX portion is done through html. Notice also that backslashes are now double backslashes. You can press "Evaluate" for more problems or redesign the code to allow student select the number of problems.

2015-05-18 01:41:45 -0600 edited answer How to set matplotlib backend from SageTeX?

I'm not really sure I understand the question (why not use LaTeX and sagetex for plotting instead of matplotlib?) but here is an example from the matplotlib site modified to run through LaTeX using sagetex with sizes modified via the solution you pointed out (which didn't work for you):

import matplotlib as mpl
pgf_with_rc_fonts = {
"": "serif",
"font.serif": [],                   # use latex default serif font
"font.sans-serif": ["DejaVu Sans"], # use a specific sans-serif font

import matplotlib.pyplot as plt
plt.rcParams['font.size'] = 6.
plt.text(0.5, 3., "serif")
plt.rcParams['font.size'] = 3
plt.text(0.5, 2., "monospace", family="monospace")
plt.rcParams['font.size'] = 24
plt.text(2.5, 2., "sans-serif", family="sans-serif")
plt.rcParams['font.size'] = 16.
plt.text(2.5, 1., "comic sans", family="Comic Sans MS")
plt.rcParams['font.size'] = 8.
plt.xlabel(u"µ is not $\\mu$")
Sagetex let's you use matplotlib in creating pictures. 
This is a modification of an example comes from:
and it's running in \LaTeX \,with the power of the sagetex package.

When I ran the code in SagemathCloud I didn't get the comic-sans font (perhaps it's not available in SMC?!?) but everything else seems in order and font sizes are modified. I don't see how Tikz is use here.

But the examples shown on that page aren't particularly "LaTeX-like" as the page seems to indicate. If you use LaTeX for the typesetting and Sage for calculations, such as is done for the Cantor function in the answer by DJP then you're getting the LaTeX control over the picture and sagetex is performing the calculations needed for the plot. This solves the problem of being LaTeX friendly while avoiding matplotlib (why is matplotlib so necessary?), giving pictures in tikzpicture environment which look soooo much better.