Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42178
| References | <bce771a2-733b-4e51-8141-8344a26592e1@googlegroups.com> |
|---|---|
| Date | 2013-03-28 14:16 -0400 |
| Subject | Re: Differentiation in Python |
| From | David Robinow <drobinow@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3906.1364494571.2939.python-list@python.org> (permalink) |
On Thu, Mar 28, 2013 at 8:17 AM, <zingbagbamark@gmail.com> wrote: > How do I differentiate(first order and 2nd order) the following equations in python. I want to differentiate C wrt Q. > > C = (Q**3)-15*(Q**2)+ 93*Q + 100 """ Years ago, when I actually worked for a living, I would have done something like this: """ coeffs = [1, -15, 93, 100] num_coeffs = len(coeffs)-1 deriv = [coeffs[i]*(num_coeffs-i) for i in range(num_coeffs)] print(deriv) """ The above is somewhat obscure and requires one to add some documentation. Who wants to do that? Below is a version using numpy. You get the numpy docs for free. """ import numpy as np p = np.poly1d(coeffs) deriv_np = np.polyder(p) print(deriv_np) # or print(list(deriv_np))
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Differentiation in Python zingbagbamark@gmail.com - 2013-03-28 05:17 -0700 Re: Differentiation in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-28 12:35 +0000 Re: Differentiation in Python David Robinow <drobinow@gmail.com> - 2013-03-28 14:16 -0400
csiph-web