8 ms·
How to make homework more fun: Matlab to Ruby
- adambard 13y agoI never did find a solution to the performance problem when it comes to writing numeric code in Ruby. I ended up doing most of my Matlab-suggested assignments in Python with numpy instead.
- vjoel 13y agoI used to do a lot of scientific programming in ruby. I got around the slowness of the interpreter by generating C code on the fly. You don't have to give up Ruby as the DSL and utility language. It's the best of both worlds, if you can invest the time to set up the code generating machinery. As I posted on the coderwall discussion: If you are working with continuous systems (ODEs) or hybrid systems (ODEs plus discrete state transitions and dynamic dataflow networks), then you might be interested in RedShift. For example, here's a simulation of a simple thermostat controller: https://github.com/vjoel/redshift/blob/master/examples/thermostat.rb https://github.com/vjoel/redshift/blob/master/examples/therm.... (I am the author of RedShift. You can find my RubyConf 2009 presentation on the confreaks site.)
- whitewhim 13y agoAlong the same vein whenever I'm doing my physics homework I like to take the sample code whether it's R, Matlab,c etc. And convert it to python/numpy/scipy. I find I get a much deeper understanding that way and working with ipython notebook is a great workflow for prototyping.
- jfsantos 13y agoSciRuby is not on par with alternative such as NumPy/SciPy and Octave, but NMatrix (its linear algebra lib) seems to be nice: https://github.com/SciRuby/nmatrix https://github.com/SciRuby/nmatrix
- frozenport 13y agoYour homework is weird, because you are just evaluating a function instead of evaluating Maxwell's equations. Check out FDTD.
- Kronopath 13y agoOr you could just use Octave, which is an open-source Matlab clone that has almost all its core features: https://www.gnu.org/software/octave/ https://www.gnu.org/software/octave/
- ISL 13y agoAgreed. My thesis work is entirely within Octave. It gets the job done, and anyone anywhere can review my work. Some of MATLAB's toolkits are very nice, but day-to-day work is easily covered by Octave.
- jordigh 13y agoOctave is GNU, and the GNU project prefers to speak of free software than open source: http://www.gnu.org/philosophy/open-source-misses-the-point.html http://www.gnu.org/philosophy/open-source-misses-the-point.h... The philosophical distinction matters a lot to me. I don't work on Octave because I think this is a better development model. I work on it because I think we should all be free to read and share our code and our algorithms.
- FireBringer 13y agoOctave is good if you have to write matlab compatible code (or just like matlab and don't have access to it). The new kid on the block Julia[1] is actually pretty nice and as someone who has written a lot of matlab code is quite similar and easy to learn. If you don't need or want syntax similar to matlab python+scipy+numpy+matplotlib is pretty great. I was stuck with matlab for most of my work though because of simulink+control systems toolbox and preexisting codebase. [1]: http://julialang.org/ http://julialang.org/
- vog 13y ago> If you don't need or want syntax similar to matlab python+scipy+numpy+matplotlib is pretty great. Yes, Python is a great alternative here. Especially for more complex computations, the advantages of a very well designed generic language play very well with the specialized math stuff.
- Pxtl 13y ago
- blutack 13y agoFreeMAT is a really good OS clone of Matlab. http://freemat.sourceforge.net/ http://freemat.sourceforge.net/
- deleted 13y ago[deleted]
- jostmey 13y agoMatlab and several related programming languages are designed for carrying out mathematical calculations. Ruby is designed to be a multi-purpose language that has found a niche in Web-development. My advice is to use the right tool for the job, and not to try and force a round cylinder into a square hole.
- ovis 13y agoNah - use whatever tools you enjoy. This assignment doesn't look particularly numerically-demanding, and it looks like Ruby handles it fine.
- kmanzana 13y agoI agree. I really enjoy Ruby and it made my homework assignment much more fun so that's why I went with it. Obviously has its limitations.
- jurassic 13y agoIf the OP was able to run his homework files just by monkeypatching a few classes, I think that shows requiring Matlab for the assignment was massive overkill. Unless you're using the toolboxes (which they weren't), what does Matlab give you that you can't get in free language?
- RodericDay 13y agoI'm in engineering and only at the very very end on some "advanced" Control Systems classes did we even touch the toolboxes. Everything else, from Numerical Methods to Vibrations to lab report creation would've been handled by IPython and pylab much better. I envy upcoming generations tbh.
- fnordfnordfnord 13y agoFor whatever language(s) you choose to base your course curricula around, you have to have a progression from "hello world" type exercises, to moderately complicated, and on to "go and make a thing"
- kmanzana 13y agoThis was the original intent of my professor by assigning us this exercise. As a developer, I'm not her typical electrical engineering student though
- fnordfnordfnord 13y agoAnd you decided to go be awesome. Which is awesome.
- vog 13y agoAs far as I have oberseved, Python is more widely used than Ruby as a scientific tool. The reasons are great libraries like numpy, scipy and sympy (for symbolic expressions). Also, I think the standard library of Python is better designed more consistent.
- kmanzana 13y agoDidn't realize Python had so much to offer for scientific and numerical usage. I'm definitely going to have to check that stuff out. Thanks!