ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 13 Jun 2020 04:03:56 +0200Can I express an abstract, symbolic range of reals?https://ask.sagemath.org/question/51935/can-i-express-an-abstract-symbolic-range-of-reals/Hello,
I'm very new at sage.
I'd like to express a range like range(-3.0,3.0,0.02) but with symbols for all the parameters, like range(a,b,delta), that displays nicely with show(). I would like to be able to substitute in floats at some later stage.
a. I'm not sure what a conventional symbolic expression for a range of floats is
b. Not sure how to express it in SageMath.
My goal is to be able to express constructing a chain rule over a finite input range. I seem to be able to express the chaining of functions ok, but am getting stuck with what i'm calling the constant function which is this range. If I use the range(-3.0,3.0,0.02) I get swamped by the output.
P.S. I don't want to use a built-in differentiate, I'm going to use finite differences.
Cheers...banksiaboySat, 13 Jun 2020 04:03:56 +0200https://ask.sagemath.org/question/51935/Difference between RealNumber and RealLiteralhttps://ask.sagemath.org/question/36798/difference-between-realnumber-and-realliteral/I discovered this tonight.
sage: L = srange(-1,1,.01)
sage: type(L[50])
<type 'sage.rings.real_mpfr.RealNumber'>
sage: type(-.5)
<type 'sage.rings.real_mpfr.RealLiteral'>
and hence
sage: -.5 in L
False
In some sense I'm cool with that, but in another sense I'm very annoyed. (Especially since I probably should have known about it but missed this.) So ... what exactly is the difference between these types, and when should they each be used? You might see my confusion given this result:
sage: L[50] in RR
True
sage: -.5 in RR
True
Oh, and this is really awesome:
sage: type(RealNumber(-.5))
<type 'sage.rings.real_mpfr.RealLiteral'>
Also, perhaps if anyone ever makes the full list of real numbers types as in [Question 9950](https://ask.sagemath.org/question/9950/what-are-the-different-real-numbers-in-sage/), one could add these.kcrismanFri, 03 Mar 2017 03:21:57 +0100https://ask.sagemath.org/question/36798/range and division : unexpected behaviorhttps://ask.sagemath.org/question/32891/range-and-division-unexpected-behavior/Consider the following snippet :
N=5
# code 1
for n in range(N,N+1):
for k in range(0,n):
print k/n
print '-'*10
# code 2
n=N
for k in range(0,n):
print k/n
I was expecting code 1 and code 2 to print the same output. This is not the case :
0
0
0
0
0
----------
0
1/5
2/5
3/5
4/5
In the first case, `k/n` is Python-evaluated as an integer division, in the second case, `k/n` is Sage-evaluated as a fraction. Can someone elaborate please ?
I only notice that substituting `srange(N,N+1)` to `range(N,N+1)` fixes the problem.
candideSun, 27 Mar 2016 11:28:01 +0200https://ask.sagemath.org/question/32891/Error while trying to use srange and for loopshttps://ask.sagemath.org/question/26992/error-while-trying-to-use-srange-and-for-loops/ I am trying to execute some instructions containing for loops and variables in sranges. The instructions are simple; yet I keep getting an error message and can't figure out where the error is. My program is at https://cloud.sagemath.com/projects/f9c3371c-3682-4811-b236-f62976d8fa24/files/scratch.sagews. I am trying to use this simple program to see if I have correctly executed a much larger program.C. ThompsonMon, 01 Jun 2015 01:25:40 +0200https://ask.sagemath.org/question/26992/srange bug?https://ask.sagemath.org/question/9117/srange-bug/Lets say that we want a list of the numbers 0,0.001,0.002 ... 2
if we use srange after some values we have rounding errors:
srange(0,2,0.001)
... 1.13799999999999, 1.13899999999999, 1.13999999999999, 1.14099999999999, 1.14199999999999...
why? Is this a bug? A quick solution is to use numpy:
import numpy as np
p=np.arange(0,2,0.001);p
array([ 0.00000000e+00, 1.00000000e-03, 2.00000000e-03, ...,
1.99700000e+00, 1.99800000e+00, 1.99900000e+00])
but the question remains... why srange doesn't work correctly?
(tested on Sage 5.0.1 & 5.0 & 4.7.2)koukourikosWed, 27 Jun 2012 21:57:09 +0200https://ask.sagemath.org/question/9117/