Ask Your Question

dazedANDconfused's profile - activity

2023-05-20 02:34:03 +0200 received badge  Civic Duty (source)
2023-05-19 22:17:53 +0200 answered a question How to substitute a value into an expression without evaluation to convert it to LaTex?

There are several ways to do it and you'll have to decide on which suits you best. First method: Direct use of sympy. Th

2023-05-18 03:27:12 +0200 edited answer Code for guessing formula for integer sequence

With respect to sequences, look into the Lagrange (interpolation) polynomial for a set points which is here in the docum

2023-05-18 03:22:40 +0200 edited answer Code for guessing formula for integer sequence

With respect to sequences, look into the Lagrange (interpolation) polynomial for a set points which is here in the docum

2023-05-18 03:21:06 +0200 answered a question Code for guessing formula for integer sequence

With respect to sequences, look into the Lagrange (interpolation) polynomial for a set points which is here in the docum

2023-02-18 15:10:25 +0200 commented answer How to draw CubeGraph(5) better?

Thanks, I didn't notice that. I use circular layout when I am not happy with positioning. I've edited my answer to show

2023-02-18 15:08:14 +0200 edited answer How to draw CubeGraph(5) better?

I use 3 useful tweaks in making graphs: 1. Adjust the vertex size, 2. Adjust the distance between vertices, 3. arrange t

2023-02-18 04:41:55 +0200 answered a question How to draw CubeGraph(5) better?

I'm not sure what you mean by overlapping vertices. The issue I see is that the labels are too big for the vertices. Wit

2022-09-19 23:58:42 +0200 commented answer How to randomly generate a quadratic, monic, irreducible polynomial over ring of integers ZZ with small coefficients?

Good idea! I revised code to do that.

2022-09-19 23:58:00 +0200 edited answer How to randomly generate a quadratic, monic, irreducible polynomial over ring of integers ZZ with small coefficients?

You haven't made it clear how big integers can be and still be small. The following code can easily be modified as neede

2022-09-19 03:10:54 +0200 edited answer How to randomly generate a quadratic, monic, irreducible polynomial over ring of integers ZZ with small coefficients?

You haven't made it clear how big integers can be and still be small. The following code can easily be modified as neede

2022-09-19 03:09:44 +0200 answered a question How to randomly generate a quadratic, monic, irreducible polynomial over ring of integers ZZ with small coefficients?

You haven't made it clear how big integers can be and still be small. The following code can easily be modified as neede

2022-08-30 23:33:13 +0200 commented answer Plotting a periodic function

Nice, +1: I especially like the one using trig functions.

2022-08-30 00:08:29 +0200 commented answer Plotting a periodic function

Yes, I was going to add another while loop which kept adding 2 for values <-1 if I needed to graph the negative porti

2022-08-29 16:18:35 +0200 marked best answer Plotting a periodic function

I want to plot a function that is abs(x) for -1<= x <= 1 and repeats to create a sawtooth shaped function. With the code

def h(x):
    while x>1:
        x=x-2
    return abs(x)
h(4.3)

The Sage sell server tells me the value is 0.300000000000000, which is what I want as h(4.3)=h(2.3)=h(.3)=abs(.3) However, when I tried to plot h(x) with

def h(x):
    while x>1:
        x=x-2
    return abs(x)
plot(h(x),x,0,5)

The plot looks like abs(x), so that h(4.3) now appears to be 4.3. What has gone wrong? How can I properly plot the h(x) I want?

EDIT: A points plot gives me the output I am expecting, which is different than plot(h(x),x,0,5).

def h(x):
    while x>1:
        x=x-2
    return abs(x)

 points([(x, h(x)) for x in srange(0,5,.01)], pointsize=20)
2022-08-29 16:18:32 +0200 commented answer Plotting a periodic function

Good explanation! It clears up some misunderstandings I had.

2022-08-29 03:33:01 +0200 edited question Plotting a periodic function

Plotting a periodic function I want to plot a function that is abs(x) for -1<= x <= 1 and repeats to create a sawt

2022-08-29 02:54:24 +0200 asked a question Plotting a periodic function

Plotting a periodic function I want to plot a function that is abs(x) for -1<= x <= 1 and repeats to create a sawt

2022-05-13 20:21:30 +0200 received badge  Taxonomist
2022-03-04 16:56:36 +0200 received badge  Nice Answer (source)
2022-01-13 07:30:40 +0200 received badge  Nice Question (source)
2022-01-13 07:29:37 +0200 marked best answer Points making up a plot

I'd like to get the list of points that make up a sage plot so I can process it through LaTeX (eg pgfplots) and get a better looking plot. This post here is essentially what I'm looking. I didn't really understand the code but came up with this:

x,y=var('x,y')
f(x,y)=x^2-y^2
p = implicit_plot(f(x,y)==3,(x,-3,3),(y,-3,3),plot_points=300)
P = p.matplotlib()
R = P.get_children()[1]
S = R.collections[0]
r = S.get_paths()[0]
v = r.vertices
xvals = v[:,0]
yvals = v[:,1]

Change the function to f(x,y)=x^2+y^2 and the code works properly. But the example above only gives me the list of points for the left half of the hyperbola. How can I get the list of points when the graph is disconnected? Can that be extended to get the list of points if there are multiple graphs in the same plot?

2021-03-12 13:17:59 +0200 received badge  Popular Question (source)
2021-01-01 21:53:54 +0200 received badge  Popular Question (source)
2020-12-19 03:13:24 +0200 commented question Graph plot: vertex attributes, node size, arrow head for loops, why are loops on nodes

LaTeX make results look beautiful, Sage handles the math, and sagetex provides a way of using Sage en route to producing a graph like that. The quality of the image you have given is not possible in a Sage Cell Server. You said, "I do not understand how to set the vertex attributes, the size of the nodes, and so on.". That is covered in the documentation here. This page will show you the sort of output you should expect with just Sage. At the top of that page it gives you a link for LaTeX drawing of graphs. That page gives you output of LaTeX code. The output can be realized through LaTeX using sagetex which I linked to in my earlier comment. A Sage Cell server won't do this.

2020-12-19 03:12:53 +0200 answered a question Graph plot: vertex attributes, node size, arrow head for loops, why are loops on nodes

LaTeX is used to make results look beautiful, Sage handles the math, and sagetex provides a way of using Sage en route to producing a graph like that. The quality of the image you have given is not possible in a Sage Cell Server. You said, "I do not understand how to set the vertex attributes, the size of the nodes, and so on.". That is covered in the documentation here. This page will show you the sort of output you should expect with just Sage. At the top of that page it gives you a link for LaTeX drawing of graphs. That page gives you output of LaTeX code. The output can be realized through LaTeX using sagetex which I linked to in my earlier comment. A Sage Cell server will not give you the LaTeX image resulting from the code.

2020-12-18 05:06:01 +0200 commented question Graph plot: vertex attributes, node size, arrow head for loops, why are loops on nodes

If you're interested in producing professional looking graphs then LaTeX is the way to go using the packages tkz-graph and tkz-berge. These can work with Sage via the sagetex package. You can see some examples here or here or, for digraphs here. In these cases, the edges vertex sizes, labels, etc are set through LaTeX. The cooperation between Sage and LaTex is not "incorporated completely" but does a decent job.

2020-11-16 01:42:13 +0200 commented question Is there any way to use SageMath on macOS Big Sur??

There's always Cocalc as well if you have an internet connection.

2020-10-24 01:02:41 +0200 answered a question Tiny results of find root

Those two roots are both approximations of 0. If possible, you should always seek to solve theoretically and numerically. If the answers agree then you feel confident everything was done correctly. If the answers disagree then you have to look deeper. The roots of the function are when it is equal to 0, so you need to solve the equation (x^2)*cos(2*x)=0. That means either x=0 or cos(2*x)=0. Now cos(x)=0 at +/- (2k+1)pi/2 so cos(2x)=0 at +/- (2k+1)pi/4. Since we're looking for roots over [-10,10], this means our roots are 0, +/- pi/4, 3pi/4,....11pi/4. Your answer +/- 0.7853981633974483, 2.356194490192345, 3.9269908169872405, 5.497787143782152, 7.0685834705770345, 8.639379797371932 are the roots +/- pi/4, 3pi/4,....11pi/4. What's missing is 0. In your search for roots over [-.1,0] and [0,.1] you've found -7.755114791616843e-09 and 7.755114791616843e-09.

You mention inflection points but usually we calculate inflection points by taking the second derivative but from your answers I see you are setting the first derivative equal to 0. Where the derivative is 0 (or undefined) are usually called the critical values. If you rewrite the second answer as x=cot(2x) and think about the graphs of cot(2x) and x and where the intersect you'll get an idea of the number of answers. Try plotting

A = plot(cot(2*x),-10,10,ymax=10, ymin=-10, detect_poles=True)
B = plot(x,-10,10,ymax=10, ymin=-10,color='red')
(A+B).show()

Which looks like:

image description

There is no way to solve that equation analytically. However, since you know where, approximately, the roots are you can use find_root , documentation here to find them. Your first positive solution would be found by, for example, find_root(cot(2*x)-x,.01,.8) to get 0.5384369931559019. What should become apparent is that learning mathematical theory can help you to use SAGE like an expert.

2020-10-20 02:38:18 +0200 commented question Why does plot choke on x to the 1/3 power, when it will calculate it just fine?

Following the answers, both plot(sgn(x)*abs(x)^(1/3),(x,-10,10)), which uses sgn once and the more natural plot(lambda x: RR(x).nth_root(3), (-10, 10)) work. The RR is telling Sage that real roots are expected. See documentation here.

2020-10-20 00:39:00 +0200 commented question Why does plot choke on x to the 1/3 power, when it will calculate it just fine?

This question has been covered before, see here. Remember your order of operation: exponentiation doesn't apply to the negative. You've taken a positive cube root and then made it negative. If you try (-10)^(1/3).n() then you get 1.07721734501594 + 1.86579517236206*I.

2020-10-19 02:05:23 +0200 commented answer plot of sine, parabola intersection works but solve makes no sense

Most equations have no clean solution and must be evaluated with numerical approximations. This is one of them. Even polynomials can cause problems.

2020-10-08 03:01:20 +0200 answered a question Plot legend in latex from equations in Sagemath

I fiddled around and got it to work by changing the legend_label:

var("x_1","x_2")
eq1=solve(3*x_1+4*x_2==14,x_2)
eq2=solve(5*x_1+6*x_2==-8,x_2)
eq3=solve(4*x_1-7*x_2==18,x_2)
eq4=solve(2*x_1-3*x_2==-8,x_2)
b=10
p=plot([eq1[0].rhs(),eq2[0].rhs(),eq3[0].rhs(),eq4[0].rhs()], (x_1, 0,b),color=["#c72b91","#2b37c7", "#cb7b2b","#2bcb4b"],axes_labels=["$x_1$","$x_2$"],legend_label=[r"$%s$"%latex(eq1[0].rhs()),r"$%s$"%latex(eq2[0].rhs()),r"$%s$"%latex(eq3[0].rhs()),r"$%s$"%latex(eq4[0].rhs())])
show(p)

This is the result: image description

Since there are several equations in the legend, I use a list. Looking at that part of the code, r"$%s$"%latex(eq1[0].rhs()) accomplishes the task by first getting the latex code for eq1[0].rhs() with latex(eq1[0].rhs()) followed by inserting that in for the string r"$%s$. The r is for a raw string and since its a formula, LaTeX needs it between dollar signs.

It seems a bit awkward, maybe others have a more efficient way.

2020-09-12 17:31:44 +0200 commented question Cocalc: change texmf.cnf file

I've emailed Cocalc support for help. Should I delete this question?