Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-26 Thread Oscar Benjamin
On 25 April 2016 at 15:35, Derek Klinge wrote: > > Although I see the value of relative error, I am just as interested in > absolute error (though admittedly they are directly related values). I was referring to relative error because the relative error is the same at each step making the calcula

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-25 Thread Derek Klinge
A couple thoughts. I think my original approach would be faster than binary search for finding the minimum value of N needed to get a decimal level of absolute accuracy from Euler's number. Here is my reasoning: EulerlersNumber(13).LimitMethod() - math.e < .1 and EulersNumber(135).LimitMethod - mat

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-25 Thread Oscar Benjamin
On 25 April 2016 at 08:39, Gregory Ewing wrote: > Derek Klinge wrote: >> >> Also, it seems to me if the goal is to use the smallest value of n to get >> a >> particular level of accuracy, changing your guess of N by doubling seems >> to >> have a high chance of overshoot. > > > If you want to find

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-25 Thread Peter Otten
Derek Klinge wrote: > I found that the pattern of an additional digit of accuracy corresponding > to 10*n did not hold as strongly for that value (I can post data if > desired). I also got some results that seem to contradict the mathematical > definition. For example try EulersNumber(10**15).Limi

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-25 Thread Gregory Ewing
Derek Klinge wrote: Also, it seems to me if the goal is to use the smallest value of n to get a particular level of accuracy, changing your guess of N by doubling seems to have a high chance of overshoot. If you want to find the exact n required, once you overshoot you could use a binary search

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Derek Klinge
So I tried the recommended limit approach and got some interesting results. ## Write a method to approximate Euler's Number using Euler's Method import math class EulersNumber(): def __init__(self,n): self.n = n self.e = 2 def linearApproximation(self,x,h,d): # f(x+h)=f(x)+h*f'(x) return x + h *

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Derek Klinge
Actually, I'm not trying to speed it up, just be able to handle a large number of n. (Thank you Chris for the suggestion to use xrange, I am on a Mac using the stock Python 2.7) I am looking at the number of iterations of linear approximation that are required to get a more accurate representation

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Oscar Benjamin
On 24 April 2016 at 19:21, Chris Angelico wrote: > On Mon, Apr 25, 2016 at 4:03 AM, Derek Klinge wrote: >> Ok, from the gmail web client: > > Bouncing this back to the list, and removing quote markers for other > people's copy/paste convenience. > > ## Write a method to approximate Euler's Number

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Chris Angelico
On Mon, Apr 25, 2016 at 4:03 AM, Derek Klinge wrote: > Ok, from the gmail web client: Bouncing this back to the list, and removing quote markers for other people's copy/paste convenience. ## Write a method to approximate Euler's Number using Euler's Method import math class EulersNumber():

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Chris Angelico
On Mon, Apr 25, 2016 at 3:56 AM, Derek Klinge wrote: > Doesn't range(n) create a list n long? Not in Python 3. If your code is running on Python 2, use xrange instead of range. I rather doubt that's your problem, though. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Derek Klinge
Doesn't range(n) create a list n long? On Sun, Apr 24, 2016 at 10:21 AM Chris Angelico wrote: > On Mon, Apr 25, 2016 at 3:02 AM, Derek Klinge > wrote: > > My problem is this: my attempt at Euler's Method involves creating a > list of > > numbers that is n long. Is there a way I can iterate over

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Chris Angelico
On Mon, Apr 25, 2016 at 3:02 AM, Derek Klinge wrote: > My problem is this: my attempt at Euler's Method involves creating a list of > numbers that is n long. Is there a way I can iterate over the linear > approximation method without creating a list of steps (maybe recursion, I am > a bit new at t

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Chris Angelico
On Mon, Apr 25, 2016 at 3:06 AM, Derek Klinge wrote: > I think my e-mail client may be stripping the indentation, here it is with > 4-space indentation I think it is. Both your reposted versions have indentation lost. You may need to use a different client. My posts come from the Gmail web clien

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Derek Klinge
I think my e-mail client may be stripping the indentation, here it is with 4-space indentation ## Write a method to approximate Euler's Number using Euler's Method import math class EulersNumber(): def __init__(self,n): self.eulerSteps = n self.e = self.EulersMethod(self.eulerSteps) def linearApp

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Derek Klinge
Sorry about the code indentation, I was using Pythonista (iOS), and it did not have any problem with that indentation... Here is a new set of the code: ## Write a method to approximate Euler's Number using Euler's Method import math class EulersNumber(): def __init__(self,n): self.eulerSteps = n

Re: Optimizing Memory Allocation in a Simple, but Long Function

2016-04-24 Thread Chris Angelico
On Sun, Apr 24, 2016 at 1:05 PM, Derek Klinge wrote: > I have been writing a python script to explore Euler's Method of > approximating Euler's Number. I was hoping there might be a way to make > this process work faster, as for sufficiently large eulerSteps, the process > below becomes quite slow

Optimizing Memory Allocation in a Simple, but Long Function

2016-04-23 Thread Derek Klinge
I have been writing a python script to explore Euler's Method of approximating Euler's Number. I was hoping there might be a way to make this process work faster, as for sufficiently large eulerSteps, the process below becomes quite slow and sometimes memory intensive. I'm hoping someone can give m