Ask Your Question

jepstra's profile - activity

2022-03-11 06:57:01 +0200 received badge  Popular Question (source)
2021-07-18 19:48:31 +0200 received badge  Notable Question (source)
2021-04-12 09:50:47 +0200 received badge  Popular Question (source)
2020-05-01 23:18:54 +0200 received badge  Popular Question (source)
2020-03-19 02:49:16 +0200 received badge  Notable Question (source)
2019-12-12 20:35:08 +0200 received badge  Famous Question (source)
2019-06-25 16:20:42 +0200 received badge  Popular Question (source)
2019-02-23 20:09:50 +0200 received badge  Notable Question (source)
2018-11-16 12:55:20 +0200 received badge  Popular Question (source)
2018-04-22 08:57:08 +0200 commented answer Sagecell with code hosted in GitHub

@tmonteil Thank you very much for the answer. It works perfectly. However, I would like to show the input cell and also the input code, for educational purposes. I'll edit the question to include this nuance. Thanks again!

2018-04-21 17:51:40 +0200 asked a question Sagecell with code hosted in GitHub

I would like to embed a Sage Cell in a webpage whose content comes from a GitHub .py file, so that changes in this file are immediately shown in the webpage. I have tried to use javascript / jquery like this (with the standard scripts in the head) and with some variations:

<div class="sage"><script type="text/x-sage" id="sage1"></script></div>
<script>$('#sage1').load("https://rawgit.com/path_to_the_file.py");</script>

and it sometimes work, but not always. I guess it has to do with the order of all the scripts involved in the process. Which would be the most appropiate and clean way to inject such code in a Sage Cell?

EDIT: I would like to show the input cell together with the input code, for educational purposes. So the content of the input cell has to be replaced with the content of the .py file.

2018-04-03 16:35:41 +0200 received badge  Nice Question (source)
2018-03-13 11:11:37 +0200 asked a question Implicit Plot 3D - ThreeJS

I'm trying to plot several algebraic surfaces, most of which have singularities and other especial properties. Using implicit_plot3d and viewer='threejs' works fine for instance

var('x,y,z')
p=x^3+y^3+z^3+1-0.25*(x+y+z+1)^3
r=5
color='aquamarine'
s = implicit_plot3d(p==0, (x,-r,r), (y,-r,r), (z,-r,r), plot_points=50, region=lambda x,y,z: x**2+y**2+z**2<=r*r, color=color)
s.show(frame=False, viewer='threejs')

But when increasing plot_points=100, SageCell does note return any output (demo) (in a Sage Notebook, everything works fantastic). I guess the query may be too hard for SageCell...

Is there a way to optimize the code / query for SageCell to plot algebraic surfaces with acceptable quality?

2018-02-27 11:03:59 +0200 commented answer MatrixPlots with cell entries

@j.c. excellent, really!

2018-02-22 18:19:50 +0200 asked a question MatrixPlots with cell entries

Is there a nice way to combine MatrixPlot with something else to have a label in each cell such as in this picture?

image description

2018-02-15 18:07:31 +0200 commented answer plot_vector_field3d and three.js viewer

@eric_g thank you very much!!

2018-02-14 09:15:20 +0200 commented answer plot_vector_field3d and three.js viewer

Thank you very much for your comment and attention!! I'm afraid I'm not very used to the code inside Sage... but I hope I may contribute to SageMath in the future.

2018-02-13 12:56:22 +0200 asked a question plot_vector_field3d and three.js viewer

I guess there might be some mistake in my code, but I cannot use plot_vector_field3d and show the result with three.js viewer. The code is

var('x y z')
f = (x, y, z)
show(plot_vector_field3d(f, (x,-3,3), (y,-3,3), (z,-3,3), aspect_ratio=1), viewer='threejs')

and it only shows an empty box. How to explain this behaviour?

2018-01-15 16:24:26 +0200 asked a question Numerical Integral with variable params

I am trying to write some code to plot a function of an integral whose integrand depends on two variables, much like the following:

a = var('a')
b = var('b')
plot3d(numerical_integral((x+a+b), 0, 1, params=[a,b])[0],(a,0,1),(b,0,1))

This code raises an error NotImplementedError: free variable: b. Which would be the correct way to implement this code?

2018-01-02 14:25:52 +0200 commented answer Mixing %cython and @interact in one cell

@nbruin Works like a charm!! This was the way I needed to reduce the scope of the cython environment. I didn't know how to do it.

2018-01-02 14:24:26 +0200 received badge  Supporter (source)
2018-01-01 23:01:30 +0200 commented answer Mixing %cython and @interact in one cell

@emmanuel-charpentier I have added a minimal working example (of course the actual code is much larger) that does not compile neither in a Sage notebook nor a SageMathCell. Could you try it? Thank you very much!

2018-01-01 22:58:50 +0200 received badge  Editor (source)
2018-01-01 14:03:14 +0200 asked a question Mixing %cython and @interact in one cell

I'm trying to make an interactive applet to visualize the Mandelbrot Set, much in the way of the implementation of interactive fractals (wiki.sagemath.org/interact/fractal#Exploring_Mandelbrot - cannot copy full link because of not enough karma ;-))

But I'd like to embed the applet in a webpage using SageMathCell, and for this all the code must be encapsulated in just one cell, something in the following scheme

%cython
def function(...)
    ...

@interact
...

Unfortunately, %cython and @interact behave badly together, because the latter is unknown to the former (just try to join the code in the two cells of the example above or try the following minimal working example

%cython
def square(float x0):
    return x0*x0

@interact
def _(x0=-2.5):
    print(square(x0))

which, surprisingly enough, raises different errors in a online Sage Cell and in a Sage Notebook Cell)

Which would be the smartest way to mix everything up? Any suggestion is highly appreciated.

2017-12-15 17:32:39 +0200 received badge  Scholar (source)
2017-11-25 11:57:44 +0200 commented answer Factoring polynomials with symbolic expressions

@tmonteil Thank you very much! This is exactly what I needed

2017-11-24 23:52:03 +0200 received badge  Student (source)
2017-11-24 22:53:04 +0200 asked a question Factoring polynomials with symbolic expressions

This question is about writing some code that factors a desired polynomial within $\mathbb{Q}$, $\mathbb{R}$ and $\mathbb{C}$ for educational purposes.

So far, I have the following code:

@interact
def _(p = input_box(default=x^5 + x^4 - 8*x^3 + 11*x^2 - 15*x + 2, label = 'P(x) = ')):
    q.<x> = PolynomialRing(QQ, 'x')
    r.<x> = PolynomialRing(RR, 'x')
    c.<x> = PolynomialRing(CC, 'x')
    a.<x> = PolynomialRing(AA, 'x')
    qp = PolynomialRing(QQ, 'x')(p)
    print(factor(qp))
    rp = r(p)
    print(factor(rp))
    cp = c(p)
    print(factor(cp))
    ap = a(p)
    print(factor(ap))

whose output is

(x - 2) * (x^4 + 3*x^3 - 2*x^2 + 7*x - 1)
(x - 2.00000000000000) * (x - 0.147637797932293) * (x + 3.96552349222940) * (x^2 - 0.817885694297105*x + 1.70805524786870)
(x - 2.00000000000000) * (x - 0.408942847148552 - 1.24129810909174*I) * (x - 0.408942847148552 + 1.24129810909174*I) * (x - 0.147637797932293) * (x + 3.96552349222940)
(x - 2.000000000000000?) * (x - 0.1476377979322930?) * (x + 3.965523492229398?) * (x^2 - 0.8178856942971048?*x + 1.708055247868697?)

The factorization is perfect, but I would like the output to be symbolic whenever possible (ie. written with radicals instead of decimals). I know about the use of the ring 'AA' and that the numbers ending with '?' may be translated into symbolic, but I do not know the smartest way to do this.

Which would be the smartest way to achieve this goal? In the same way, ideas to improve the previous code are also welcome