Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Python/Excel for engineers

Status
Not open for further replies.

IDS

Civil/Environmental
Jun 1, 2001
3,221
I have recently been experimenting with Python + numpy and scipy; combined with PyXll to talk to Excel. It seems to me to be a good way of getting round Excel's main limitation for engineering work (i.e. the lack of good heavy-duty numerical analysis routines), although the need to work in a new language slows things down at first.

Anyone else using Python for engineering work?

Any recommended engineering applications or good documentation/help resources would be much appreciated.



Doug Jenkins
Interactive Design Services
 
Replies continue below

Recommended for you

I'm using it more and more. We've used it for scripting (running tests, controlling builds, etc.) for a while, but the big incentive lately was that we decided to abandon Matlab. A popular alternative (though not a clone in the spirit of Octave) is IPython. It's a confusing world of packages and GUIs and consoles though. Ended up installing Python(x,y) which bundles together all the important bits, though it's still not clear where to go for what.

While not directly related to Excel, I found the following two websites useful general resources:


 
Since the cost of Matlab is monotonically increasing, it would make sense that at some point in time, some people will abandon Matlab in favor of Python or Octave. I would expect, though, that Octave will be more prevalent than Python, mainly because Octave at least has some claim to compatibility with Matlab. The issue with Python would be the uncertainty of compatibility of any given routine with and given version of Python. The proliferation of Python versions would be an impediment to any company looking to have maximal compatibility with available code.

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529
 
I don't see code incompatibility as being a problem. At some point somebody will write a translator which will turn m files into py. That may not be efficient py code, but cpu time is cheap.

I write most of my matlab stuff in octave compatible code anyway, so of the two alternatives I am more likely to stick with octave. That being said it wouldn't kill me to get a working py environment up and running, as we already have large slabs of the GUI for my main programs written in py.





Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Thanks for the links LiteYear. I have also found the number of different packages confusing. I ended up installing Anaconda with Python 2.7 (although I also have WinPython 3.3 installed, which doesn't seem to cause any difficulties, so far).

My main reasons for going with Python rather than Octave were:
- It seems to be much easier to integrate with Excel (with the help of PyXll).
- The Strand7 API has interfaces for Matlab and Python, but not Octave. Trying to convert from Matlab to a partial clone, in a language I know nothing about, seemed like asking for trouble.
- Python is (it seems) more flexible, and probably has a bigger developer community.

Doug Jenkins
Interactive Design Services
 
This Python stuff sounds really interesting, but climbing the learning curve on another language is an unenvious proposition.

So I ask, what advantages does Python have over my old favs Fortran and Excel VBA?
 
This Python stuff sounds really interesting, but climbing the learning curve on another language is an unenvious proposition.

So I ask, what advantages does Python have over my old favs Fortran and Excel VBA?

I have done some stuff linking Excel to Fortran via VBA, and it worked well, but it doesn't seem to work since I moved to 64 bit Windows. It would probably be fairly simple to fix, but I haven't found the time to look at it.

The main advantages of Python are:
[ul]
[li]There are extensive libraries linking to high performance compiled code, and these seem to be under more active development than Fortran.[/li]
[li]Using PyXll it's very easy to call these libraries, either directly from a User Defined Function, or via VBA.[/li]
[li]It is also very easy to develop routines in VBA, then link to compiled routines, via PyXll and Python, for the calculation intensive bits.[/li]
[/ul]

The main disadvantage compared with linking Excel directly to a compiled language is that pure Python seems to be even slower than VBA, although there are easy to use ways to speed it up, which from my limited testing seem to work very well.

I guess the main reason for adopting Python, other than that I enjoy dabbling with this stuff, is that I see it as a way of future-proofing for the days when VBA and/or Excel become just another programming tool that old people used to use once.

Doug Jenkins
Interactive Design Services
 
I don't primarily use Python for every day use.
But, I have used it many times before for statistical calculations.

Since reading this thread I tried to use if for scientific things I would normally use Matlab or Maple, Octave for.
But, the scientific libraries for Mac OSX are a serious pain to install. With a net search this seems to be a widespread issue.
If anyone here uses Python for engineering on OSX let me know. Thanks.




"Simplicity is the ultimate sophistication." L. da Vinci
G. Coppola
 
Screw it haha. I'll just use Linux for Python. Seems to work with no issues.


"Simplicity is the ultimate sophistication." L. da Vinci
G. Coppola
 
I just remembered I used another very useful Open source computational language before.
It is very useful and similar to Octave. It although has a better interface imo than Octve.


"Simplicity is the ultimate sophistication." L. da Vinci
- Gian
 
Yup Scilab is much prettier, more modern and more actively developed than Octave. Sadly it is less compatible with Matlab. I can write Octave at home and be fairly confident that the same code will run on Matlab with very few tweeks. Converting Scilab to Matlab is nowhere near as easy.

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
I agree Greg. It's too bad that Octave is not more evolved than it is. If it were it would be the absolute choice without a doubt.


"Simplicity is the ultimate sophistication." L. da Vinci
- Gian
 
Ahh. The conversion is not without issues it seems. Had to correct the way it converts if statements.

It converted:
Code:
 if s1(i)>d1h || s1(i)<d1l 
                s1(i)=6000;
            end

to

Code:
//    %v02 = %t;  if ~s1(i)>d1h then %v02 = s1(i)<d1l;end;
  //    if %v02 then
  //      s1 = mtlb_i(s1,i,6000);
  //    end;

Also, seems that Matlab runs the code same faster. Interesting.


"Simplicity is the ultimate sophistication." L. da Vinci
- Gian
 
scilab can come with scicos if dynamic block-based modelling is your thing. It even claims to support Modelica, although that bit was quite immature when I last looked into it.

- Steve
 
I tried the block diagram dynamic modeling in scilab. It is indeed very "immature" compared to simulink.

Although, the direct programming of scripts seems to be almost on par with matlab in terms of functionality.


"Simplicity is the ultimate sophistication." L. da Vinci
- Gian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor