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.Sun, 12 May 2019 19:43:57 +0200plotting complicated functionhttps://ask.sagemath.org/question/46495/plotting-complicated-function/*I would like to approximate the sum* $$h(a,x) = \frac{-2}{n} \sum_{n=0}^{n-1} log|T_a^n(x)| $$ where $n$ is large like $n= 1000 - 5000$ and for a fixed $a$ $$T_a(x) = \Big|\frac{1}{x}\Big| - \Big\lfloor{\Big|\frac{1}{x}\Big| - 1 +a}\Big\rfloor$$
where $x \in (0,1).$
By fixing $x$ to be a value $x_0 \in (0,1)$, e.g. $x_0 = 1/\pi$, $$h(a, x_0) = h(a, 1/\pi)$$ a function of one variable, and I want to plot a 2D graph of point $(a, h(a, 1/\pi))$, by fixing $n = 2000$, for $a \in [0,1].$
I figure how to calculate the value at one given $a$ using SageMath,
for example, when $a = 1$,
T(x) = 1/x - floor(1/x)
s = 0
for k in xrange(0, 1000):
a = 0
a = nest(T, k, 0.79)
b = abs(a)
c = log(b)
s = s + c
Then $\frac{-2}{1000}s$ give the approximation for the sum when $x = 0.79$, $n = 1000$, $a = 1$.
But for plotting, I think I need to define the function $h(a, x)$ which is a summation over composition of functions. I tried to use `sum` and `symbolic_sum` but failed.
Any help how to achieve this please?PusheenMoewSun, 12 May 2019 19:43:57 +0200https://ask.sagemath.org/question/46495/Summation of simbolic variableshttps://ask.sagemath.org/question/45669/summation-of-simbolic-variables/Hi guys!
----------
I have this function on theta:
$R_{x}(\theta) = R_{tx} + \cos \theta \cdot \left( f_{vp} + \sum_{i=1}^{n} \left(p S_i \sin^2 \alpha_i \right) \right) - \sin \theta \cdot \frac{1}{2} \sum_{i=1}^{n} \left(p S_i \sin 2\alpha_i \right)$
----------
Since I cannot define an n-dimensional vector, I reduced n to 5, and wrote the following code down in SAGE:
var('alpha1, alpha2, alpha3, alpha4, alpha5'); # some angles
var('area1, area2, area3, area4, area5'); # some areas
var('Rtx, Rty'); # components of some force
var('fvp'); # modulus of yet another force
var('pv'); # wind pressure
var('theta'); # wind direction
var('i'); # variable to iterate over the angles and areas
# this vector contains all the angles
alpha = vector([alpha1, alpha2, alpha3, alpha4, alpha5]);
# this vector contains all the areas
area = vector([area1, area2, area3, area4, area5]);
Upto this point everything seems to go fine.
Then I try to define my function like this:
# The function I am trying to define, depending on the wind direction
Rx(theta) = Rtx + cos(theta) * (fvp + sum(pv * area[i] * sin(alpha[i])^2, i, 1, 5)) - sin(theta) * 1/2 * sum(area[i] * sin(2*alpha[i])^2, i, 1, 5)
And sage complains:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-4889d5aee183> in <module>()
----> 1 __tmp__=var("theta"); Rx = symbolic_expression(Rtx + cos(theta) * (fvp + sum(pv * area[i] * sin(alpha[i])**Integer(2), i, Integer(1), Integer(5))) - sin(theta) * Integer(1)/Integer(2) * sum(area[i] * sin(Integer(2)*alpha[i])**Integer(2), i, Integer(1), Integer(5))).function(theta)
sage/modules/free_module_element.pyx in sage.modules.free_module_element.FreeModuleElement.__getitem__ (/build/sagemath-x4mQwo/sagemath-7.4/sage/src/build/cythonized/sage/modules/free_module_element.c:12935)()
sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__index__ (/build/sagemath-x4mQwo/sagemath-7.4/sage/src/build/cythonized/sage/symbolic/expression.cpp:31916)()
sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._integer_ (/build/sagemath-x4mQwo/sagemath-7.4/sage/src/build/cythonized/sage/symbolic/expression.cpp:8623)()
TypeError: unable to convert i to an integer
Any ideas on what may be happening? And, Is there a way to make it work?
Apparently, my question is similar to: Symbolic function that sums over variable sequence (sorry: my karma is insufficient to post links).
Still, it is different in that I have two vectors of variables and need to define a computation using variables from both vectors. And I was trying to get it done in a different way.
Thank you for your time.
==============
EDIT:
This made the trick:
alpha = function("alpha")(i);
area = function("area")(i);
Rx=function("Rx")(theta);
sum1(i) = pv * area(i) * sin(alpha(i)^2)
sum2(i) = area(i) * sin(2*alpha(i))/2
Rx(theta) = Rtx + cos(theta) * (fvp + sum(sum1(i), i, 1, n)) - sin(theta) * sum(sum2(i), i, 1, n)
Thanks to @emmanuel-charpentierclonTue, 05 Mar 2019 16:46:13 +0100https://ask.sagemath.org/question/45669/Help summing an infinite serieshttps://ask.sagemath.org/question/40512/help-summing-an-infinite-series/I have been trying to evaluate the following series using SageMath.
sum((x^x)/(factorial(x)*exp(x)) - 1/sqrt(2*pi*x), x, 1, +oo).n()
The answer should be -0.084069508727655... (-2/3 - zeta(1/2)/sqrt(Pi)), but I get the following error when the upper limit is above 96:
RuntimeError: maximum recursion depth exceeded while calling a Python object
Is there any way SageMath could give me even the first few digits of the infinite sum? This sum seems to evaluate just fine in Maple and Mathematica, but not in any open source program I have tried, including Axiom, Maxima, PARI, and SymPy.
Any help would be greatly appreciated.
lkklSun, 07 Jan 2018 01:16:21 +0100https://ask.sagemath.org/question/40512/solving summation polynomialshttps://ask.sagemath.org/question/40125/solving-summation-polynomials/
Solving discrete logarithm problem for elliptic curves
most papers I see use Magma for solving summation polynomials, can SageMath do this?
Paul DoyleTue, 12 Dec 2017 18:14:31 +0100https://ask.sagemath.org/question/40125/Expanding summation with factorialhttps://ask.sagemath.org/question/38793/expanding-summation-with-factorial/If I do this in sage
F=sum(k^2*factorial(n), v=k, a=1, b=n+1); F
it correctly expands to what I want:
⎛ 3 2 ⎞
⎝2⋅n + 9⋅n + 13⋅n + 6⎠⋅n!
───────────────────────────
6
However, if the factorial is a function of the summed variable, it doesn't work anymore:
sage: F=sum(k^2*factorial(k), v=k, a=1, b=n+1); F
sum(k^2*factorial(k), k, 1, n + 1)
sage: F.expand_sum()
sum(k^2*factorial(k), k, 1, n + 1)
Is this the expected behavior? How can I get it to expand no matter what's inside the summation?
I'm using Sagemath 7.5, by the way.
Thank you.tomchoTue, 12 Sep 2017 07:41:11 +0200https://ask.sagemath.org/question/38793/Help finding expected value of sum of random variableshttps://ask.sagemath.org/question/32739/help-finding-expected-value-of-sum-of-random-variables/I'm very much a Sage newbie, and I'm having trouble solving for the expected value of a discrete summation. I'll admit that I'm well removed from statistics, linear algebra, and econometrics, so it might be that what I'm trying to accomplish is illogical.
Consider the following parameters:
<b>E</b> ~ N(0,1) (i.e., E is a random variable distributed standard normal)
<b>M</b> ~ U(1,*m*) (i.e., M is a uniformly distributed random variable varying between 1 and *m*)
<b>A</b> = | Σ E×M | over the interval (1,N) (or the absolute value of the summation of E times M over interval 1,N)
I'd like to find the expected value of A as a function of N (or the limit of A as N goes to infinity, assuming A converges to a real number). Can I use Sage to solve for something like this (assuming it's solvable, which I think it is based on some simulation results)?
gsu2014Tue, 08 Mar 2016 18:45:16 +0100https://ask.sagemath.org/question/32739/Summation with variables in limithttps://ask.sagemath.org/question/35701/summation-with-variables-in-limit/ Hi, I am new to Sage (and programming for that matter). I would like to sum (a1 +a3)(a1+a4)(a2+a3)(a2+a4) over all non-negative integers a1, a2, a3, a4 which satisfy 2*a1 + a3 + a4 less-than D and 2*a1 + a3 + a4 less-than D. Of course, my answer should be in terms of D (I have already declared D as a variable).
I have tried using the standard sum function, but that doesn't seem to work over more than one variable. I could try writing my sum as several sums, each over a single variable, but that seems tedious. Does sage allow for more complicated summations like the one I would like to calculate? If so, I would be grateful for an example.
I have tried searching for similar questions on this site, as well as google searching, but I have had no success.
Thank you.
Michael YWed, 23 Nov 2016 16:04:08 +0100https://ask.sagemath.org/question/35701/how to sum up the function over all permutations of variables in associative non-commutative algebrahttps://ask.sagemath.org/question/34714/how-to-sum-up-the-function-over-all-permutations-of-variables-in-associative-non-commutative-algebra/ hello, i need to sum up $\lambda_{\sigma}(a_{\sigma(1)}a_{\sigma(2)}a_{\sigma(3)}-a_{\sigma(3)}a_{\sigma(4)}a_{\sigma(5)})$ over all $\sigma\in S_5$ where $a_i$ are elements of associative non-commutative algebra.
the result should be $E_1a_1a_2a_3a_4a_5+\cdots+E_{120}a_5a_4a_3a_2a_1$
and i need to express $E_i$ in terms of $\lambda_{\sigma}$.
actualy my tartget is to find non-zero solution of $E_i=0$ for all $i$.RadmirSun, 04 Sep 2016 15:19:15 +0200https://ask.sagemath.org/question/34714/How to evaluate the infinite sum of 1/(2^n-1) over all positive integers?https://ask.sagemath.org/question/32122/how-to-evaluate-the-infinite-sum-of-12n-1-over-all-positive-integers/ I have tried
s = sum(1/(2^x-1), x, 1, oo)
s.n()
But I got
cannot evaluate symbolic expression numerically
The sum does not have a simple form, but it is finite.
So is there a way to evaluate it numerically in sage?ablmfSat, 09 Jan 2016 15:28:40 +0100https://ask.sagemath.org/question/32122/Summing primes, cannot convert to inthttps://ask.sagemath.org/question/27159/summing-primes-cannot-convert-to-int/What can I do so that the following code works:
sage: var('k')
sage: sum(nth_prime(k),k,1,10)
ValueError: cannot convert k to int
Thanks in advance!OderynFri, 19 Jun 2015 15:33:10 +0200https://ask.sagemath.org/question/27159/Summing polynomialshttps://ask.sagemath.org/question/23590/summing-polynomials/I have a ´Univariate Polynomial Ring in t over Symbolic Ring´
sage: cj_t = (-1)**(j-1)/factorial(j-1)*(-j+a)**(j-1/2)*exp(-j)*(t+j)**(-1)
How can I compute the sum over j from 1 to N?
sage: sum(cj_t,1,N)
doesn't work.
sage: sum([cj_t for j in [1..N]])
(Python syntax) doesn't work either.jjackSat, 26 Jul 2014 11:00:15 +0200https://ask.sagemath.org/question/23590/Sum a list of vectorshttps://ask.sagemath.org/question/10658/sum-a-list-of-vectors/I'm given a list of rational vectors, i.e., something like [(1,2,3), (1/2, 4, 5), (-1, 0, 0)], and I need to sum all vectors of this list.
Even though I searched a bit, I cannot find the right sage command for this task. For example, sum() does not seem to work here. At least I couldn't figure out how to apply it to a list of such type.
Of course I could use a loop and an additional variable that saves the partial sums. But there has to be a more elegant way.SamsaMon, 04 Nov 2013 05:18:21 +0100https://ask.sagemath.org/question/10658/Sage showed "TypeError: need a summation variable" when i used sum function with for loophttps://ask.sagemath.org/question/10674/sage-showed-typeerror-need-a-summation-variable-when-i-used-sum-function-with-for-loop/I try to make a summation list and the commands are below this:
> sage: var('n')
>
> sage: var('x')
>
> sage: f = (2/n)\*(sin(n\*x)\*(-1)^(n+1))
>
> sage: funclist = [sum(f,n,1,20) for n
> in range(1,3)]
but i found an error message:
> TypeError: need a summation variable
How to solve this problem?
terces907Wed, 30 Oct 2013 05:43:42 +0100https://ask.sagemath.org/question/10674/Difference between sum and for loophttps://ask.sagemath.org/question/10669/difference-between-sum-and-for-loop/Hi,
I'm currently using sage to calculate some double sums over two variables, where s runs from 1 to t-1, and t runs from 2 to 2*x+2*n+1. I initially used two nested for loops inside the following function:
def qentr(i,j,k,x,n):
s,t,sm = var('s,t,sm')
sm = 0
for t in range(2,2*x+2*n+2):
for s in range(1,t):
sm = sm + h(i,s,k,x,n)*h(j,t,k,x,n) - h(j,s,k,x,n)*h(i,t,k,x,n)
return sm
where i, j, k, x, n are all nonnegative integers. This gives me the correct values for what I am enumerating, for instance qentr(1,3,3,1,2) = 96, which is right. For some reason when I replace these for loops with two nested sums, say,
sum(sum(h(i,s,k,x,n)*h(j,t,k,x,n)-h(i,t,k,x,n)*h(j,s,k,x,n),s,1,t-1),t,2,2*x+2*n+1)
this no longer gives me the correct values. If I replace the two nested loops with this sum I get qentr(1,3,3,1,2)=196....
I wanted to replace the loops with sum in order to return an expression in x, the only way I can think to do this is with sum but this does not yield the right expression. Does anyone know why this happens? Does anyone know an alternative way I can get the function qentr() to return a polynomial in x?
The function h from above is the following:
def h(i,j,k,x,n):
r = var('r')
return binomial(j-1,i-1)-2*sum(binomial(r+i-k,i-k)*binomial(j-i-r+k-2,k-2),r,x+n+(k+1)/2+1-i,j-i)
Cheers!tommytricksMon, 28 Oct 2013 13:04:05 +0100https://ask.sagemath.org/question/10669/Binomial in a Summationhttps://ask.sagemath.org/question/10384/binomial-in-a-summation/sage: var('k')
k
sage: sum(binomial(5,k),k,0,5)
I get an error "cannot convert k to int"
But if instead I try something like sum(binomial(n,k),k,0,n), everything is just fine.
Anyone know how I can get around this?david8381Thu, 25 Jul 2013 10:28:29 +0200https://ask.sagemath.org/question/10384/