Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'skip:[ 20': 0.04; 'that?': 0.05; 'subject:Python': 0.06; '"""': 0.07; '[1,': 0.09; 'equations': 0.16; 'numpy': 0.16; 'order)': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'import': 0.22; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'obscure': 0.31; 'worked': 0.33; 'something': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'version': 0.36; 'done': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; '2nd': 0.60; 'ago,': 0.61; 'skip:n 10': 0.64; 'mar': 0.68; '100': 0.79; 'received:mail-ob0-x22d.google.com': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=fOsg3EOBfRlKUQNv6j48IAfjjwwEYvzIFwpu4VWDqnw=; b=EE3u+JV2RYXZq9ufsA4bntUMNr3C/lXyuimGwRQikkMrZtaUlLbkV+sY5QnFAxtVEv n8oue1fVmpu8Zo0tCXdGrvD2iSN5LFGx7S+5xnFLFKz91oBEYGJJpklsa98bhEQl0vII FkWQZbMHpVvZkBePCd7ObZE+0k4ixpN0xfunYkOhtfOvjslfOzjYuRF0ZAhZwxXVYaFc trDWpvScFeEuFExfCZCFdF4Flm6zzhiihp8ErDIlromjcLyFJVsHDDLQJMdSR4kkekn3 V+1ciEC0v6nMMFFAGLNSN+hodrlKN5CVrssMiZdLC7EnAkyTlJII9MxAWhT6ozAq9DKj aotg== MIME-Version: 1.0 X-Received: by 10.60.62.70 with SMTP id w6mr9003081oer.38.1364494568147; Thu, 28 Mar 2013 11:16:08 -0700 (PDT) In-Reply-To: References: Date: Thu, 28 Mar 2013 14:16:08 -0400 Subject: Re: Differentiation in Python From: David Robinow To: python-list@python.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364494571 news.xs4all.nl 6903 [2001:888:2000:d::a6]:54441 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42178 On Thu, Mar 28, 2013 at 8:17 AM, 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))