Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64391
| Date | 2014-01-21 09:05 +0100 |
|---|---|
| From | Johannes Schneider <johannes.schneider@galileo-press.de> |
| Subject | Re: matlabFunction Equivalent? |
| References | <403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5772.1390292806.18130.python-list@python.org> (permalink) |
On 20.01.2014 23: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?
>
If you don not mind installing other programs, maybe you can have a
look at sage (www.sagemath.org). That's a ComputerAlgebraSystem using
python as its base and supporting most (all?) of the python syntax and
moduls
bg,
Johannes
--
Johannes Schneider
Webentwicklung
johannes.schneider@galileo-press.de
Tel.: +49.228.42150.xxx
Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/
Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
matlabFunction Equivalent? rpi.baldum@gmail.com - 2014-01-20 14:09 -0800 Re: matlabFunction Equivalent? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-20 22:48 +0000 Re: matlabFunction Equivalent? Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-01-21 09:05 +0100
csiph-web