Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42120 > unrolled thread
| Started by | zingbagbamark@gmail.com |
|---|---|
| First post | 2013-03-28 05:17 -0700 |
| Last post | 2013-03-28 14:16 -0400 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | zingbagbamark@gmail.com |
|---|---|
| Date | 2013-03-28 05:17 -0700 |
| Subject | Differentiation in Python |
| Message-ID | <bce771a2-733b-4e51-8141-8344a26592e1@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-03-28 12:35 +0000 |
| Message-ID | <515438ff$0$29998$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #42120 |
On Thu, 28 Mar 2013 05:17:36 -0700, zingbagbamark 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 For such a simple case, you don't do it with Python, you do it with maths, and get an exact result. dC/dQ = 3*Q**2 - 30*Q + 93 d²C/dQ² = 6*Q - 30 The rule for differentiating polynomials of the form y = k*x**n is: dy/dx = (k*n)*x**(n-1) Consult a good calculus text book or on-line site for further details. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | David Robinow <drobinow@gmail.com> |
|---|---|
| Date | 2013-03-28 14:16 -0400 |
| Message-ID | <mailman.3906.1364494571.2939.python-list@python.org> |
| In reply to | #42120 |
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))
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web