Ask Your Question

sagefan's profile - activity

2020-03-08 16:42:27 -0500 received badge  Famous Question (source)
2019-11-18 19:56:45 -0500 received badge  Popular Question (source)
2019-01-18 11:29:46 -0500 received badge  Famous Question (source)
2019-01-18 11:29:46 -0500 received badge  Notable Question (source)
2019-01-03 10:41:00 -0500 received badge  Famous Question (source)
2018-12-25 05:23:11 -0500 received badge  Notable Question (source)
2018-07-06 07:17:20 -0500 received badge  Famous Question (source)
2018-04-06 10:25:52 -0500 received badge  Famous Question (source)
2018-03-08 23:45:25 -0500 received badge  Notable Question (source)
2018-03-08 23:45:25 -0500 received badge  Famous Question (source)
2017-12-07 22:58:47 -0500 received badge  Popular Question (source)
2017-12-06 11:51:08 -0500 received badge  Notable Question (source)
2017-12-03 09:26:23 -0500 received badge  Famous Question (source)
2017-05-17 12:59:42 -0500 received badge  Popular Question (source)
2017-04-06 15:39:01 -0500 received badge  Notable Question (source)
2017-04-06 15:39:01 -0500 received badge  Popular Question (source)
2017-03-26 02:55:11 -0500 received badge  Popular Question (source)
2016-12-30 09:42:41 -0500 received badge  Famous Question (source)
2016-10-14 16:27:36 -0500 received badge  Popular Question (source)
2016-10-05 14:51:25 -0500 received badge  Notable Question (source)
2016-10-05 13:52:37 -0500 received badge  Famous Question (source)
2016-10-03 04:27:03 -0500 received badge  Great Question (source)
2016-10-02 09:14:18 -0500 received badge  Notable Question (source)
2016-05-26 01:42:14 -0500 received badge  Popular Question (source)
2016-05-23 12:47:08 -0500 received badge  Notable Question (source)
2016-04-08 04:18:12 -0500 received badge  Notable Question (source)
2016-03-02 14:58:21 -0500 received badge  Popular Question (source)
2016-03-02 14:58:21 -0500 received badge  Notable Question (source)
2016-03-02 14:58:21 -0500 received badge  Famous Question (source)
2015-11-18 18:05:53 -0500 received badge  Notable Question (source)
2015-08-22 18:57:32 -0500 received badge  Notable Question (source)
2015-06-16 15:37:59 -0500 received badge  Famous Question (source)
2015-03-26 22:12:33 -0500 marked best answer How to change linestyle of 2d vector field plots

How can I change the linewidth and the arrow tips of a 2d vector field plot?

2015-03-26 22:12:10 -0500 marked best answer How to check if a square root is irrational

What's the easiest way in sage to check if the square root of a given rational number (for example 1,671 or 2,56) is irrational.

2015-03-26 22:12:02 -0500 marked best answer Animate plot of two piecewise functions

Consider a slightly modified version to the workaround to this question

sage: k = 5
sage: f = Piecewise([[(-2,1),k],[(1,4),x]])
sage: g =  Piecewise([[(-2,1),1],[(1,4),2*x]])
sage: P = plot(f,color='green')
sage: Q = plot(g,linestyle='--')
sage: P+Q

Is it possible to animate this plot say with k ranging from 0 to 10?

I tried:

k = 5
f = Piecewise([[(-2,1),k],[(1,4),x]])
g =  Piecewise([[(-2,1),1],[(1,4),2*x]])
P = plot(f,color='green')
Q = plot(g,linestyle='--')
X = P+Q
b = animate([X for k in srange(0,10)],xmin=0,xmax=4,figsize=[5,5])
b
b.show()

but it calculates for minutes and doesn't show up a result. (I tried examples from the documentation which worked fine).

I also tried this:

t = var('t')
k = var('k')

def f(t,k):
    if t <=1:
        return t
    else:
        return k


def g(t,k):
    if t <=1:
        return 1
    else:
        return 2*t

@interact
def _(k=(0,10)):
    p1=plot(f(t,k),(t,0,3),ymax=10,ymin=0,color='green')
    p2=plot(g(t,k),(t,0,3))
    show(p1 + p2)

However the piecewise defined functions don't work in this case.

2015-03-26 22:12:02 -0500 marked best answer Two piecewise defined functions in one plot

Is it possible to plot 2 piecewise defined functions to one plot?

I tried:

f = Piecewise([[(-2,1),1],[(1,4),x]])
g =  Piecewise([[(-2,1),1],[(1,4),2*x]])
plot([f,g])

but I get the following error message:

{{{id=6|
x_1 = Piecewise([[(-100,t_R),v_0*t],[(t_R,t_R + v_0/a),-1/2*a*(t-t_R)^2 + v_0*t],[(t_R + v_0/a,100),v_0^2/(2*a) + v_0*t_R]])
x_2 = Piecewise([[(-100,2*t_R),v_0*t + s_S],[(t_R,2*t_R + v_0/a),-1/2*a*(t-2*t_R)^2 + v_0*t + s_S],[(2*t_R + v_0/a,100),v_0^2/(2*a) + v_0*(2*t_R) + s_S ]])
///
}}}

{{{id=7|
xp = plot([x_1(t),x_2(t)]);
xp.show(axes_labels=["Zeit t in s","x_1 in m"],xmin=0,xmax=v_0/t_R + t_R,ymin=0)
///
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_137.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eHAgPSBwbG90KFt4XzEodCkseF8yKHQpXSk7CnhwLnNob3coYXhlc19sYWJlbHM9WyJaZWl0IHQgaW4gcyIsInhfMSBpbiBtIl0seG1pbj0wLHhtYXg9dl8wL3RfUiArIHRfUix5bWluPTAp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single')
  File "", line 1, in <module>

  File "/tmp/tmpjQcRVV/___code___.py", line 3, in <module>
    xp = plot([x_1(t),x_2(t)]);
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/functions/piecewise.py", line 648, in __call__
    raise ValueError,"Value not defined outside of domain."
ValueError: Value not defined outside of domain.
}}}

{{{id=13|
f = Piecewise([[(-2,1),1],[(1,4),x]])
g =  Piecewise([[(-2,1),1],[(1,4),2*x]])
plot([f,g])
///
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_145.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZiA9IFBpZWNld2lzZShbWygtMiwxKSwxXSxbKDEsNCkseF1dKQpnID0gIFBpZWNld2lzZShbWygtMiwxKSwxXSxbKDEsNCksMip4XV0pCnBsb3QoW2YsZ10p"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single')
  File "", line 1, in <module>

  File "/tmp/tmpSARQLu/___code___.py", line 5, in <module>
    exec compile(u'plot([f,g])' + '\n', '', 'single')
  File "", line 1, in <module>

  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 657, in wrapper
    return func(*args, **kwds)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 504, in wrapper
    return func(*args, **options)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/plot.py", line 3067, in plot
    G = _plot(funcs, (xmin, xmax), **kwds)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/plot.py", line 3105, in _plot
    funcs, ranges = setup_for_eval_on_grid(funcs, [xrange], options['plot_points'])
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/misc.py", line 138, in setup_for_eval_on_grid
    return fast_float(funcs, *vars,**options), [tuple(range+[range_step]) for range,range_step in zip(ranges, range_steps)]
  File "fast_eval.pyx", line 1357, in sage.ext.fast_eval.fast_float (sage/ext/fast_eval.c:8418)
  File "fast_eval.pyx", line 1377, in sage.ext.fast_eval.fast_float (sage/ext/fast_eval.c:8704)
AttributeError: PiecewisePolynomial instance has no attribute '__float__'
}}}
2015-03-26 22:12:02 -0500 marked best answer import old mupad files

Is it possible to import mupad worksheets in sage?

2015-03-26 22:11:52 -0500 marked best answer Apply a function to a list

Is there a simply syntax to apply a function like f(x) = x*exp(x) to a list of points L for example L=[1,2,3,4,19]. I want to be able to write something like f(L) which is a new list with the elements [f(1),f(2),f(3),f(4),f(19)]

2015-03-26 22:08:41 -0500 marked best answer Construct function out of extrema, roots...

Is there a way in sage to construct and plot a smooth function which has a given set of data:

  • the minima $(miA_1,miA_2)$, $(miB_1,miB_2)$,...
  • the maxima $(maA_1,maA_2)$, $(maB_1,maB_2)$,...
  • the roots $(nA1,nA2)$, $(nA1,nA2)$...
  • a given behaviour for $x \to \pm \infty$.
2015-03-26 22:08:30 -0500 marked best answer Add a start, stop and pause button to a sage animation

Is it possible to add start, stop and pause buttons to a sage animation?

2015-03-26 22:08:05 -0500 marked best answer Swap coordinates of list elements

Suppose I have list like

L = [(2,3), (4,5), (6,7)]

What's the easiest way to transform it to this list:

L'=[(3,2),(5,4),(7,5)]

i.e. swap the coordinates in each entry.

2015-03-26 22:08:01 -0500 marked best answer Plot picewise function + infinity, error message

If I define a piecewise function from -infinity to +infininty, and I want to plot it, I get an error message like below. Any ideas how to fix this? Any workarounds?

f = Piecewise([[(-infinity,1),1],[(1,+infinity),2]])
plot(f)
Traceback (most recent call last):
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 657, in wrapper
    return func(*args, **kwds)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 504, in wrapper
    return func(*args, **options)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/plot.py", line 3058, in plot
    G = funcs.plot(*args, **original_opts)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/functions/piecewise.py", line 1018, in plot
    return sum([plot(f, a, b, *args, **kwds) for (a,b),f in self.list()])
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 657, in wrapper
    return func(*args, **kwds)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 504, in wrapper
    return func(*args, **options)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/plot.py", line 3077, in plot
    G = _plot(funcs, (xmin, xmax), *args, **kwds)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/plot.py", line 3180, in _plot
    data = generate_plot_points(f, xrange, plot_points, adaptive_tolerance, adaptive_recursion, randomize)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/plot.py", line 4180, in generate_plot_points
    data = srange(*ranges[0], include_endpoint=True)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/misc.py", line 1149, in srange
    L = list(xsrange(start,end,step,universe,check,include_endpoint,endpoint_tolerance))
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/misc.py", line 1242, in xsrange
    icount = int(math.ceil(float(count) - endpoint_tolerance))
ValueError: cannot convert float NaN to integer
2015-03-10 10:39:38 -0500 commented answer latex Function Prevent Simplification

Is there any new feature today which makes this more easy?

2015-02-07 15:50:05 -0500 received badge  Popular Question (source)
2015-01-03 16:11:19 -0500 commented question Redundant brackets in exponents and sagetex

@John Palmieri Indeed I have choosen the wrong minimal example. See my updated question above.

2015-01-03 09:40:54 -0500 asked a question Redundant brackets in exponents and sagetex

If I do

$\sage{1/exp(x)}$

in sagetex, it typeset's it as $e^{(-x)}$ instead of $e^{-x}$. How to fix this?

By the way: Is it possible to make sagetex to typeset the Euler Number automatically as $\mathrm{e}$ instead of $e$?

2014-12-11 04:20:58 -0500 marked best answer disable sage notebook password

I find it annoying to have to type a password to access my local sage notebook worksheets. Is there any way to disable the password? It makes no sense for my local installation.