Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64377 > unrolled thread

matlabFunction Equivalent?

Started byrpi.baldum@gmail.com
First post2014-01-20 14:09 -0800
Last post2014-01-21 09:05 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  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

#64377 — matlabFunction Equivalent?

Fromrpi.baldum@gmail.com
Date2014-01-20 14:09 -0800
SubjectmatlabFunction Equivalent?
Message-ID<403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com>
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?

[toc] | [next] | [standalone]


#64379

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-01-20 22:48 +0000
Message-ID<mailman.5762.1390258149.18130.python-list@python.org>
In reply to#64377
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

[toc] | [prev] | [next] | [standalone]


#64391

FromJohannes Schneider <johannes.schneider@galileo-press.de>
Date2014-01-21 09:05 +0100
Message-ID<mailman.5772.1390292806.18130.python-list@python.org>
In reply to#64377
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web