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


Groups > comp.lang.python > #64379

Re: matlabFunction Equivalent?

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: matlabFunction Equivalent?
Date 2014-01-20 22:48 +0000
References <403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.5762.1390258149.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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