Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5942527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:15:57+00:00 2026-05-22T16:15:57+00:00

I’m trying to plot a function in python that has infinite sum in it.

  • 0

I’m trying to plot a function in python that has infinite sum in it. Now, since there are no infinities in computing, for my upper bound I can choose a really big number, and that’s fine.

So I tried to plot it:

from scitools.std import *
from math import *
import numpy as np

def f1(t):
    return 0.5*(1+sum((4**(2*n)*cos(2*n*t))/(e**16*factorial(n)) for n in xrange(0,10**100)))

t = linspace(0, 35, 10000)
y1 = f1(t)

plot(t, y1)

xlabel(r'$\tau$')
ylabel(r'P($\tau$)')
legend(r'P($\tau$)')
grid(True)

And I tried to decrease the xrange (or range), and increase the linspace (from 0, 35 in more than 1000 points), but I’m getting either:

OverflowError: long int too large to convert to int

or

OverflowError: range() result has too many items

So what seems to be the problem here? How can I make the sum big? Is the syntax of the sum correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:15:58+00:00Added an answer on May 22, 2026 at 4:15 pm

    That loop can’t possibly end during your lifetime. 10 ** 100 is a really really enormous number. It’s bigger than the number of particles in the universe, it’s bigger than the number of the tiniest time periods that have passed since the creation of the universe. On an impossibly fast computer – 3 * 10 ** 46 millennia for the loop to complete. To calculate an infinite sum you’d wish to calculate until the sum has stopped changing significantly (e.g. the summands have fallen under certain very small threshold).

    Also, xrange and range in Python 2 are limited to the platform’s long integers, which means that you can’t have numbers higher than 2 ** 31 on a 32 bit machine and 2 ** 63 on a 64 bit one, (the latter is still too big to ever complete in your lifetime), this is why you get an OverflowError in Python 2. In Python 3 you’d get no error, but the summation will continue forever.

    And calculation factorial of such a large number is even slower, so you don’t have a chance to ever exceed the maximum even on a 32 bit machine.

    Search for a function for calculating infinite sums, or do it yourself

    >>> from __future__ import division
    >>> import itertools
    >>> from math import factorial, cos, e
    >>> for t in [0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1]:
    ...     summables = ((4 ** (2 * n) * cos(2 * n * t)) / (e ** 16 * factorial(n)) 
    ...                  for n in itertools.count())
    ...     print 0.5 * (1 + sum(itertools.takewhile(lambda x: abs(x) > 1e-80, summables)))
    ... 
    1.0
    0.973104754771
    0.89599816753
    0.77928588758
    0.65382602277
    0.569532373683
    0.529115621076
    0.512624956755
    0.505673516974
    0.502777962546
    0.501396442319
    

    Also, I do not recognize the formula, but is this supposed to be (e ** 16) * factorial(n) or e ** (16 * factorial(n))? I just want to point out that you’ve written the former because of the other answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.