Mathcad like environment in Python?

A forum for general discussion of the Python programming language.

Mathcad like environment in Python?

Postby hrs » Sat May 04, 2013 10:50 pm

Does anyone here know of a Mathcad like IDE or such that allows you to program equations in symbolic form? This should be interleaved with regular Python. I think Sympy isn't what I want because it seems to output symbolic equations whereas I would like them to be part of the code. Barring that, the availability of Greek letter in code would be great.
hrs
 
Posts: 86
Joined: Thu Feb 07, 2013 9:26 pm

Re: Mathcad like environment in Python?

Postby setrofim » Sat May 04, 2013 11:53 pm

hrs wrote: Barring that, the availability of Greek letter in code would be great.

You can use Greek letters (or any other character with a unicode code point) in Python source, provided you set the encoding of the source files appropriately.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Mathcad like environment in Python?

Postby micseydel » Sun May 05, 2013 12:39 am

I believe Sympy can accomplish what you're talking about. Could you give an example of what you're trying to do, and how you believe Sympy is failing to do it?
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1262
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Mathcad like environment in Python?

Postby memilanuk » Sun May 05, 2013 5:02 am

Perhaps Sage would do what you are looking for...
memilanuk
 
Posts: 7
Joined: Wed Feb 20, 2013 7:16 pm

Re: Mathcad like environment in Python?

Postby hrs » Sun May 05, 2013 9:29 am

setrofim wrote:You can use Greek letters (or any other character with a unicode code point) in Python source, provided you set the encoding of the source files appropriately.

Wow, how cool, thanks! I was completely unaware of that.

micseydel wrote:I believe Sympy can accomplish what you're talking about. Could you give an example of what you're trying to do, and how you believe Sympy is failing to do it?

I'm trying to do things like this
http://imageshack.us/photo/my-images/7/formula1s.png/
which turns into difficult to read and error prone(Ijust found a bug in it) code like this
Code: Select all
P0_comp_in = P0_ambient * (1 + eff_inlet * air_speed**2 / (2 * CP_AIR * T0_ambient))**(GAMMA_AIR / (GAMMA_AIR - 1))

Now, in my actual code I've replaced (GAMMA_AIR / (GAMMA_AIR - 1)) with a single exponent since I use it alot but I left it in here to illustrate the point.

I only gave Sympy a cursory glance and saw examples of it outputting equations in symbolic form and assumed it wouldn't do what I want. I'll have a closer look at both Sympy and Sage.
Thanks.
hrs
 
Posts: 86
Joined: Thu Feb 07, 2013 9:26 pm

Re: Mathcad like environment in Python?

Postby hrs » Sun May 05, 2013 10:04 am

Using Python 2.7.3 on linux utf-8 produces a SyntaxError. Any ideas?
http://imageshack.us/f/94/utftest.png/

I'm posting a screenshot because it seems that the SQL database chokes on my post input.
hrs
 
Posts: 86
Joined: Thu Feb 07, 2013 9:26 pm

Re: Mathcad like environment in Python?

Postby setrofim » Sun May 05, 2013 3:09 pm

Using non-ASCII characters in identifier names is only supported from Python 3.0 onwards. In eariler versions, you can only use them in literal strings and comments.

The use of non-ASCII characters in identifer names is generally discouraged. If someone else tries to read the file (or you try to read it on a different machine), their text editor may not honor the coding clause and try to parse it with a different encoding so that chareacters would not display correctly; or the font the editor is using may not support those code points, so they would just see placeholder glyphs.

If you want to imporve readability of your formulas, break them down into multiple lines e.g.
Code: Select all
exponent = GAMMA_AIR / (GAMMA_AIR - 1)
ratio = (eff_inlet * air_speed**2) / (2 * CP_AIR * T0_ambient)
P0_comp_in = P0_ambient * (1 + ratio) ** exponent

(obviously, it's better to use names that relate to the formula for the intermediate varibles, rather than "exponent" and "ratio").
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Mathcad like environment in Python?

Postby hrs » Sun May 05, 2013 5:28 pm

Ah, ok. So then it's time to cross the bridge to python3 I guess.

Ps. My use of symbolic is probably incorrect because it might imply symbolic equation solving. What I meant is to just write formulas in code as you would see them in a book.
hrs
 
Posts: 86
Joined: Thu Feb 07, 2013 9:26 pm


Return to General Discussions

Who is online

Users browsing this forum: Majestic-12 [Bot], W3C [Linkcheck] and 3 guests