Not at all for numerical calculations / matrix math etc.
No, the language is grotesque for numerical calculations. It might be good at doing matrix computations, but that doesn't mean the language isn't hideous. And it isn't that good at matrix computations, either, because it's so shit at memory management, reading fucking plaintext from a file, anything having to do with the most elementary data structures, handling errors, ....
There are free alternatives to Matlab for literally anything that Matlab is good at that perform at least as good as Matlab does.
Oh for Christ's sake. Here's math.js, copied and pasted from docs:
// create an array and a matrix
const array = [[2, 0], [-1, 3]] // Array
const matrix = math.matrix([[7, 1], [-2, 3]]) // Matrix
// perform a calculation on an array and matrix
math.square(array) // Array, [[4, 0], [1, 9]]
math.square(matrix) // Matrix, [[49, 1], [4, 9]]
// perform calculations with mixed array and matrix input
math.add(array, matrix) // Matrix, [[9, 1], [-3, 6]]
math.multiply(array, matrix) // Matrix, [[14, 2], [-13, 8]]
It's even easier with C++:
#include <iostream>
#include <Eigen/Dense>
// Create a 2x2 matrix called a.
Matrix2d a;
a << 1, 2,
3, 4;
// Create a 2x2 matrix called b using an alternative but just as easy syntax.
MatrixXd b(2,2);
b << 2, 3,
1, 4;
//Their sum
a + b;
//Their difference.
a - b;
// Increment a by amount b.
a += b;
// Make some 3d vectors.
Vector3d v(1,2,3);
Vector3d w(1,0,0);
// Mother fucking scalar product.
w - 2*v;
// Vector product. BAM!
w*v;
It's almost like you've never even fucking seen vectorized calculations done in C++.
And I'm not even sure if you are using that word right. MathWorks sure as hell doesn't. You see, in the world of numerical computing, vectorization means using processor instructions (sometimes called SIMD instructions) that are designed to work on multiple data elements at the same time, whereas in the land of Matlab it means not using a for loop. Which, to be fair, is good advice in most languages, but especially in Matlab where interpreted code is apparently transcribed by a hamster before execution on an abacus.
The Eigen C++ code above automatically uses SIMD instructions. In fact, it automatically uses the most powerful SIMD instructions on the many different hardware platforms it supports.
Meanwhile, Matlab... might use SIMD instructions maybe? depending on the computation you're doing. And despite being a CAS specifically focused on linear algebra, Matlab only gained this ability in, like, 2011. I kid you not. And it only got it then because it adopted MKL. Which means, for those keeping track at home, that only those operations for which Matlab uses MKL (plus FFT, apparently) use SIMD. How... cutting edge.
You said MATLAB was an ugly language for matrix calculations and then responded with some extremely basic operations in C++ using an external library. I don’t know what point that’s supposed to be proving. No one in research uses C++ as an alternative for MATLAB for a ton of reasons, one being that you have to compile it. This should be obvious to you.
I mean you claimed MATLAB was worse at managing memory than C++ which is nonsensical. C++ is slowly dying specifically because it doesn’t manage memory
and yes ‘vectorized’ in MATLAB means using vector operations instead of for loops so it is optimized better. If you really need to use SIMD you can always write a MEX function
You give C++ and Javascript as examples of languages in which "vectorized" arithmetic is ugly, and when someone literally "gets back to you" with explicit examples in both languages showing how trivial it is to do those computations, you can't fathom what the point is? Here, let me quote you to make it easier to see what the point of those examples is:
"I mean saying it is uglier than C++ is kind of silly. Try doing simple vectorized calculations from MATLAB but in C++ and get back to me on that. And JavaScript? Come on man lol."
You see, the point is that, despite your claim to the contrary, doing "simple vectorized calculations" in C++ and JavaScript is trivially easy, extremely readable, and at least in the case of C++, much more performant, not to mention free. To spell it out for you, the point is, you have obviously never tried to do "vectorized" computations in anything other than Matlab. Which gives weight to the argument that the only reason you think Matlab is any good at the things you think it's good at because you are ignorant of the alternatives. I don't know whether or not that's true. Maybe you aren't. But damn, those examples really make a strong case.
No one in research uses C++ as an alternative for MATLAB for a ton of reasons, one being that you have to compile it. This should be obvious to you.
Obviously many scientists don't use C++ for their research. My reading of the anti-Matlab crowd is, that's exactly the whole complaint, that is, that scientists make really bad decisions about which software to use. In my experience, scientists are the worst at using the wrong tool for the job, which the widespread use of Matlab testifies to. They just use whatever their advisor tells them to use, because they don't know any better. So you end up with this mish-mash spaghetti code in Matlab that took some poor graduate student 9 months to code when they could have learned how to do it in Python from scratch in a week with a simple "import sklearn" or whatever. Hey, I don't know you, so I don't know if that's you or not, but I mean, your comments aren't painting a picture of a scientist whose very well-informed with respect to the available software tools in the numerical computing space. (Scientists don't use C++ because it has to be compiled?! Really?!)
Of course, tons of scientists do use C++ and Python for their research. Maybe in your field the only thing people use is Matlab, and so "if all you have is a hammer, everything looks like a nail." But if you branch out a bit, you'll find a ton of statisticians, data scientists, and ecologists using R, HPC people using C++, mathematicians using Python, Pari, and Mathematica, physicists using a lot of C/C++ and Mathematica, etc. From my point of view, scientists in other fields have the same problem of not using the right tool for the job. For example, I think R is the Matlab of ecology. Nothing against R, but it has its strengths and weaknesses, and it just shouldn't be used for everything under the sun. Sure, do your data analysis and plotting in R.
They didn’t show any examples of simple vectorized equations that you can do in MATLAB. They loaded an external library and showed that you can multiply matrices together which is not what I was talking about.
Arguing that C++ or JavaScript are just as good as MATLAB for this stuff is just wrong. There is no debate here.
To spell it out for you, the point is, you have obviously never tried to do “vectorized” computations in anything other than Matlab.
You don’t know what you’re talking about. In fact it actually appears you haven’t used MATLAB very much. Are you aware of how many built-in functions MATLAB has? Especially with the toolboxes. And they’re all optimized already.
There are many reason to not use MATLAB, but the claim that it is an ugly language for linear algebra etc.. is plainly wrong and using C++ as the paragon is hilarious
edit: As an example, let's try and create a diagonal matrix with the values being the square roots of 1 2 3 and print it out
In C++ with eigen:
#include <iostream>
#include "Eigen/Dense"
int main()
{
Eigen::Matrix< double, 3, 1> v ;
v << 1, 2, 3;
Eigen::Matrix< double, 3, 3> m = v.array().sqrt().matrix().asDiagonal());
std::cout << m << "\n";
return 0;
}
The equivalent in MATLAB:
m = sqrt(Diag([1 2 3]))
You should probably not comment on things you don't know anything about.
You said MATLAB was an ugly language for matrix calculations and then responded with some extremely basic operations in C++
... Yes I did? Because you literally said, and I'm going to quote you here, "Try doing simple vectorized calculations from MATLAB but in C++ and get back to me on that. And JavaScript? Come on man lol." And so I did simple vectorized calculations from Matlab but in C++ and then got back to you, you know, like you said. Except they the operations were actually vectorized in C++, whereas Matlab uses serial operations for matrix addition and subtraction. So where is the confusion here? Maybe here:
in C++ using an external library.
Oh, so it really just sounds like you're confused because you don't know how software works. Eigen is a C++ library. To do matrix/vector math in C++, you use a C++ library like Eigen, which, if I may reiterate, is written in C++. I wonder, do you know how Matlab does it's matrix arithmetic? For some of its operations, it uses Intel's Math Kernel Library (MKS), and MKS is in turn written in C/C++ and Fortran (and probably a little assembly language). Now I'm wondering what you think "external library" means.
The only part of Matlab that is actually optimized for modern processors is the part that uses MKS, because MKS is optimized for modern processors using SIMD.
This is basically where I realize you don't know how computers work. Not that there's anything wrong with that. It's just an unusual feature of someone who is arguing the superiority of one computer programming language over another.
I mean you claimed MATLAB was worse at managing memory than C++ which is nonsensical. C++ is slowly dying specifically because it doesn’t manage memory
At this point I am starting to doubt that you have ever used Matlab, much less C++. Even the hardcore Matlab apologists on this thread acknowledge how shitty Matlab is at memory management. Again, not that there's anything wrong with that, either. It's just, well, an unusual feature of someone who is arguing Matlab's superiority.
and yes ‘vectorized’ in MATLAB means using vector operations instead of for loops so it is optimized better. If you really need to use SIMD you can always write a MEX function
Aaaaand here's where I realize that it's not going to help much to explain things to you, so I might as well go back through my response and point out all the places I realize how little you know about what you are talking about, because it's a little more fun to be an asshole than to talk to a brick wall. Normally I have a twinge of guilt about indulging in assholerly solely for the entertainment value, but based on your comment history I can tell you are truly a horrible bigoted asshole, so I'm actually ok with this one.
You know you've lost the argument when you're digging through someone's post history for dirt. I don't need to dig up any of your stuff because you're already coming across as a hilariously arrogrant blowhard who doesn't actually know anything.
Oh, so it really just sounds like you're confused because you don't know how software works. Eigen is a C++ library. To do matrix/vector math in C++, you use a C++ library like Eigen, which, if I may reiterate, is written in C++. I wonder, do you know how Matlab does it's matrix arithmetic? For some of its operations, it uses Intel's Math Kernel Library (MKS), and MKS is in turn written in C/C++ and Fortran (and probably a little assembly language). Now I'm wondering what you think "external library" means.
Yes, and the point is that you have to download it, install it, and link against. In MATLAB, it's all there already. Hence, it is easier to use and less ugly. This isn't complicated. Please, bring up the MKL (or as you call it, MKS) again. That's really helping you so much.
This is basically where I realize you don't know how computers work.
You originally said MATLAB was an ugly language compared to C++, and I said it wasn't. Now you're talking about SIMD and instruction sets for some reason and being patronizing about it which is funny. It isn't complicated stuff man. You don't actually know what MATLAB is doing in this respect because it's all proprietary. There is an entire Parallel Computing Toolbox for MATLAB which I'm sure you're an expert in. https://www.mathworks.com/products/parallel-computing.html
At this point I am starting to doubt that you have ever used Matlab, much less C++.
lol okay man. You definitely aren't projecting. I'll repeat the example I used in another reply to show how much better MATLAB is at these types of calculations:
try and create a diagonal matrix with the values being the square roots of 1 2 3 and print it out
In C++ with eigen:
#include <iostream>
#include "Eigen/Dense"
int main()
{
Eigen::Matrix< double, 3, 1> v ;
v << 1, 2, 3;
Eigen::Matrix< double, 3, 3> m = v.array().sqrt().matrix().asDiagonal());
std::cout << m << "\n";
return 0;
}
The equivalent in MATLAB:
m = sqrt(Diag([1 2 3]))
Oh shit, look at that? You're completely wrong. So kindly, shut the fuck up.
This code has the major advantage of being strongly typed and giving a sparse matrix. It's arguably much more readable than the Matlab equivalent, but some people prefer fewer keystrokes, so which is better is more a matter of taste. If you'd rather just print it to the screen, do this:
"In short: do not use the auto keywords with Eigen's expressions, unless you are 100% sure about what you are doing. In particular, do not use the auto keyword as a replacement for a Matrix<> type."
(not that either of those expressions would be equivalent to the MATLAB one anyways)
1
u/I_Feel_It_Too Aug 06 '19
No, the language is grotesque for numerical calculations. It might be good at doing matrix computations, but that doesn't mean the language isn't hideous. And it isn't that good at matrix computations, either, because it's so shit at memory management, reading fucking plaintext from a file, anything having to do with the most elementary data structures, handling errors, ....
There are free alternatives to Matlab for literally anything that Matlab is good at that perform at least as good as Matlab does.