Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106164
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: sympy |
| Date | 2016-03-31 16:55 +0200 |
| Organization | None |
| Message-ID | <mailman.264.1459436170.28225.python-list@python.org> (permalink) |
| References | <733f5f0d-9b4e-4023-897b-e1f2730c39cb@googlegroups.com> <56fbcd01$0$1599$c3e8da3$5496439d@news.astraweb.com> <99b7cf43-50ff-4de7-8de0-e324658682bf@googlegroups.com> <56fbf7e7$0$1591$c3e8da3$5496439d@news.astraweb.com> <244e1277-e105-4419-a449-7f2012c6d78e@googlegroups.com> |
Poul Riis wrote:
> Den onsdag den 30. marts 2016 kl. 17.59.49 UTC+2 skrev Steven D'Aprano:
>> On Thu, 31 Mar 2016 02:23 am, Poul Riis wrote:
>>
>> > What I intend to do is to let sympy find the derivative of some
>> > welldefined function and next define the foundation derivative as a
>> > normal function so that I can calculate numerical values or even make a
>> > graph.
>>
>>
>> I'm glad you explained what you *actually* wanted, because I was going to
>> guess that you wanted to evaluate the derivative at x = 3:
>>
>>
>> py> ftext.evalf(subs={x:3})
>> -0.0600000000000000
>>
>>
>>
>> --
>> Steven
>
> ... However, the sympy way seems to be about 70 times slower than using
> the derivative calculated 'by hand' (try the example below). Can it be
> done in a more efficient way?
Hm, the two functions fmsympy() and fm() do not return the same value:
$ python -i sympy_diff.py
10000 evaluations with sympy : dt1 = 0.7178411483764648
10000 evaluations without sympy: dt2 = 0.10177111625671387
>>> fm(42)
cos(42)
>>> fmsympy(42)
-0.399985314988351
What's the point of that benchmark?
> Poul Riis
>
>
>
> from sympy import *
> from time import *
> x=Symbol('x')
> ftext=diff(sin(x),x)
>
> def fmsympy(t):
> return ftext.evalf(subs={x:t})
>
> def fm(t):
> return cos(t)
>
> nloop=10000
> tstart=time()
> # nloop evaluations with sympy
> for i in range(0,nloop):
> a=fmsympy(1)
> dt1=time()-tstart
>
> # nloop evaluations without sympy
> tstart=time()
> for i in range(0,nloop):
> a=fm(1)
> dt2=time()-tstart
>
> print(nloop,' evaluations with sympy : dt1 =',dt1)
> print(nloop,' evaluations without sympy: dt2 =',dt2)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sympy Poul Riis <priisdk@gmail.com> - 2016-03-30 04:17 -0700
Re: sympy Ben Finney <ben+python@benfinney.id.au> - 2016-03-30 22:29 +1100
Re: sympy Ned Batchelder <ned@nedbatchelder.com> - 2016-03-30 04:39 -0700
Re: sympy Steven D'Aprano <steve@pearwood.info> - 2016-03-30 23:56 +1100
Re: sympy Poul Riis <priisdk@gmail.com> - 2016-03-30 08:23 -0700
Re: sympy Robert Kern <robert.kern@gmail.com> - 2016-03-30 16:29 +0100
Re: sympy Steven D'Aprano <steve@pearwood.info> - 2016-03-31 02:59 +1100
Re: sympy Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-31 17:49 +1300
Re: sympy Poul Riis <priisdk@gmail.com> - 2016-03-30 23:51 -0700
Re: sympy Poul Riis <priisdk@gmail.com> - 2016-03-31 03:57 -0700
Re: sympy Peter Otten <__peter__@web.de> - 2016-03-31 16:55 +0200
Re: sympy Chris Angelico <rosuav@gmail.com> - 2016-04-01 04:05 +1100
Re: sympy Peter Otten <__peter__@web.de> - 2016-03-31 19:51 +0200
Re: sympy Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-03-31 19:59 +0100
Re: sympy Poul Riis <priisdk@gmail.com> - 2016-03-31 14:33 -0700
Re: sympy Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-03-31 23:26 +0100
csiph-web