Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'from:addr:yahoo.co.uk': 0.04; 'output': 0.05; 'scipy': 0.05; 'expressions': 0.07; 'variables': 0.07; '1200,': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sub': 0.09; 'url:github': 0.09; 'python': 0.11; 'language.': 0.14; '1400': 0.16; '[y,': 0.16; 'equation': 0.16; 'matlab': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:skip:m 10': 0.16; 'symbols': 0.16; 'thoughts?': 0.16; 'language': 0.16; 'wrote:': 0.18; 'hey': 0.18; 'variable': 0.18; 'all,': 0.19; 'trying': 0.19; 'seems': 0.21; 'import': 0.22; 'header:User-Agent:1': 0.23; 'math': 0.24; "haven't": 0.24; 'references': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; "i'm": 0.30; 'code': 0.31; 'derivatives': 0.31; 'equivalent.': 0.31; 'symbolic': 0.31; 'this.': 0.32; 'know.': 0.32; 'could': 0.34; "can't": 0.35; 'etc': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'subject:?': 0.36; 'turn': 0.37; 'to:addr:python-list': 0.38; 'short': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'expression': 0.60; 'skip:y 20': 0.60; 'free': 0.61; 'new': 0.61; 'range': 0.61; 'email addr:gmail.com': 0.63; 'our': 0.64; 'here': 0.66; 'hand': 0.80; 'pasting': 0.84; 'url:master': 0.84; 'do:': 0.91; 'inefficient': 0.91; 'that),': 0.91; 'mistakes': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: matlabFunction Equivalent? Date: Mon, 20 Jan 2014 22:48:48 +0000 References: <403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-187-12.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com> 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390258149 news.xs4all.nl 2878 [2001:888:2000:d::a6]:42237 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64379 On 20/01/2014 22:09, rpi.baldum@gmail.com wrote: > Hey all, > > I'm new at Python, so if you see any mistakes feel free to let me know. > > I'm trying to take a symbolic expression and turn it into a variable equation or function. I think that just an expression of variables would be preferable. > > I have a range equation which I form using symbols and then take various derivatives of it. I then want to have these derivatives on hand to use for various functions, but short of using sub every time or just copy pasting from the console output (I don't want to do that), I can't find an efficient way to do this. Matlab had matlabFunction which was really handy, but I don't think Python has an equivalent. > > ######## > import numpy as np > import scipy as sp > import sympy as sy > import math as ma > > x, y, z, x_s, y_s, z_s, theta, theta_dot, x_dot, y_dot, z_dot = sy.symbols('x y z x_s y_s z_s theta theta_dot x_dot y_dot z_dot') > > rho = (x**2 + y**2 + z**2 + x_s**2 + y_s**2 + z_s**2 - 2*(x*x_s + y*y_s)*sy.cos(theta) + 2*(x*y_s - y*x_s)*sy.sin(theta) - 2*z*z_s)**(0.5) > > rho_dot = (x*x_dot + y*y_dot + z*z_dot - (x_dot*x_s + y_dot*y_s)*sy.cos(theta) + theta_dot*(x*x_s + y*y_s)*sy.sin(theta) + (x_dot*y_s - y_dot*x_s)*sy.sin(theta) + theta_dot*(x*y_s - y*x_s)*sy.cos(theta) - z_dot*z_s)/rho > > drho_dx = sy.diff(rho, x) > > drho_dy = sy.diff(rho, y) > > drho_dz = sy.diff(rho, z) > > #I then want drho_dx, etc to be variable expressions with x, y, z, etc as variables instead of symbols or numbers. I could do: > > x, y, z = 1200, 1300, 1400 #m > > drho_dx = subs([x, x], [y, y], [z, z]) > > #but this seems inefficient to do multiple times. Thoughts? > There are references to MatlabFunction in code here https://github.com/scipy/scipy/tree/master/scipy/io/matlab but I haven't the faintest idea as to whether or not it does what you want, sorry :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence