Ask Your Question

sagefan's profile - activity

2023-07-26 15:21:57 +0100 received badge  Famous Question (source)
2021-04-18 04:39:51 +0100 received badge  Notable Question (source)
2021-04-18 04:39:51 +0100 received badge  Popular Question (source)
2021-04-05 07:41:57 +0100 received badge  Notable Question (source)
2021-02-20 20:07:00 +0100 received badge  Popular Question (source)
2021-02-20 20:07:00 +0100 received badge  Notable Question (source)
2020-12-19 01:34:57 +0100 received badge  Notable Question (source)
2020-07-02 08:22:25 +0100 received badge  Notable Question (source)
2020-05-28 13:37:18 +0100 received badge  Popular Question (source)
2020-03-08 22:42:27 +0100 received badge  Famous Question (source)
2019-11-19 02:56:45 +0100 received badge  Popular Question (source)
2019-01-18 18:29:46 +0100 received badge  Notable Question (source)
2019-01-18 18:29:46 +0100 received badge  Famous Question (source)
2019-01-03 17:41:00 +0100 received badge  Famous Question (source)
2018-12-25 12:23:11 +0100 received badge  Notable Question (source)
2018-07-06 14:17:20 +0100 received badge  Famous Question (source)
2018-04-06 17:25:52 +0100 received badge  Famous Question (source)
2018-03-09 06:45:25 +0100 received badge  Famous Question (source)
2018-03-09 06:45:25 +0100 received badge  Notable Question (source)
2017-12-08 05:58:47 +0100 received badge  Popular Question (source)
2017-12-06 18:51:08 +0100 received badge  Notable Question (source)
2017-12-03 16:26:23 +0100 received badge  Famous Question (source)
2017-05-17 19:59:42 +0100 received badge  Popular Question (source)
2017-04-06 22:39:01 +0100 received badge  Notable Question (source)
2017-04-06 22:39:01 +0100 received badge  Popular Question (source)
2017-03-26 09:55:11 +0100 received badge  Popular Question (source)
2016-12-30 16:42:41 +0100 received badge  Famous Question (source)
2016-10-14 23:27:36 +0100 received badge  Popular Question (source)
2016-10-05 21:51:25 +0100 received badge  Notable Question (source)
2016-10-05 20:52:37 +0100 received badge  Famous Question (source)
2016-10-03 11:27:03 +0100 received badge  Great Question (source)
2016-10-02 16:14:18 +0100 received badge  Notable Question (source)
2016-05-26 08:42:14 +0100 received badge  Popular Question (source)
2016-05-23 19:47:08 +0100 received badge  Notable Question (source)
2016-04-08 11:18:12 +0100 received badge  Notable Question (source)
2016-03-02 21:58:21 +0100 received badge  Popular Question (source)
2016-03-02 21:58:21 +0100 received badge  Notable Question (source)
2016-03-02 21:58:21 +0100 received badge  Famous Question (source)
2015-11-19 01:05:53 +0100 received badge  Notable Question (source)
2015-08-23 01:57:32 +0100 received badge  Notable Question (source)
2015-06-16 22:37:59 +0100 received badge  Famous Question (source)
2015-03-27 04:12:33 +0100 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-27 04:12:10 +0100 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-27 04:12:02 +0100 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-27 04:12:02 +0100 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-27 04:12:02 +0100 marked best answer import old mupad files

Is it possible to import mupad worksheets in sage?

2015-03-27 04:11:52 +0100 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-27 04:08:41 +0100 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-27 04:08:30 +0100 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-27 04:08:05 +0100 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.