468,537 Members | 1,479 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

C++ vs. Matlab

Hi!

I am a master student in (geo)physics at the University of Copenhagen
and part of a study group on C++ as a scientific programming language.

I, and the other students in the group, have previously used MatLab in
different courses to solve problems, and find it very easy to use.

This has led us to the discussion: When should we use C++ instead of
MatLab? When is C++ superior to MatLab - and when is it the other way
around?

The discussion goes on both the time consumption (in programming and
running the program) and capabilities of the two languages (can the one
language do something the other can't).

I guess you can say that the philosophy behind our discussion is: it
does not help to own some really good tools if you do not know the right
situation to apply them!

Please note that I have posted this is both comp.lang.c++ and
comp.soft-sys.matlab.

Thank, Lars.
Nov 22 '05 #1
6 21874
Lars Christiansen wrote:
Hi!

I am a master student in (geo)physics at the University of Copenhagen
and part of a study group on C++ as a scientific programming language.

I, and the other students in the group, have previously used MatLab in
different courses to solve problems, and find it very easy to use.

This has led us to the discussion: When should we use C++ instead of
MatLab? When is C++ superior to MatLab - and when is it the other way
around?

The discussion goes on both the time consumption (in programming and
running the program) and capabilities of the two languages (can the one
language do something the other can't).

I guess you can say that the philosophy behind our discussion is: it
does not help to own some really good tools if you do not know the right
situation to apply them!

Please note that I have posted this is both comp.lang.c++ and
comp.soft-sys.matlab.

Thank, Lars.


C++ is a general purpose tool that can be used to do anything. For
example, it could be used to create a product like Matlab!

Matlab is a special-purpose tool that saves the user lots of time - much
faster development time for problems that it supports, but at the cost
of larger and slower programs.

I often use both Matlab and C++ in the same program. The C++ is added
via a DLL to speed up especially important computations and to provide
interfaces to other programs. The Matlab portion of my product is only
one program - there are ten other (C++) programs in the product that
acquire data, control hardware, and display real-time spectra.

--
Scott McPhillips [VC++ MVP]

Nov 22 '05 #2

"Lars Christiansen" <la**@tiggerlars.dk> wrote in message
news:43*********************@dread16.news.tele.dk. ..
Hi!

I am a master student in (geo)physics at the University of Copenhagen
and part of a study group on C++ as a scientific programming language.

I, and the other students in the group, have previously used MatLab in
different courses to solve problems, and find it very easy to use.

This has led us to the discussion: When should we use C++ instead of
MatLab? When is C++ superior to MatLab - and when is it the other way
around?

Thank, Lars.


Hi Lars
Your question is hard to answer because you are comparing a
numerical analysis tool with a programming language C++. Lets
assume that you already have a suitable C++ library. Then you
can 1- use Maltab, 2- use the C++ lib or 3- write your own C++ lib.
In this case I would use Matlab if I wanted a quick solution especially
if it had complcated graphical output. I would use the C++ lib if the
numeric part was only a snall part of a much larger simulation written in
C++. I would also use the lib if I had to make hundreds of copys i.e.
you can't copy the $1600 matlab program.
That leaves #3 .. write it yourself in C++. OK if it's less than 1000
lines,
it may take you two months and help you develop your C++ skills. If its
over
1000 lines - forget it.
Go to my website and download ppLinear

www.pecos-place.com

here is a library that does most of the linear algebra functions of Matlab.
look at the 28 header files. There are about 6000 lines of implementation
to go with them. This is not something you should take on if you are a
geoligist
or physicist -- no kudos -- no money are achieved.

regards....pecos pe***@cminet.net
Nov 22 '05 #3
Hi Lars,

Good question, one that we have also struggled with from time to time. But I
don't think the answer is all that difficult. From my experience, under most
cercumstances it does not pay off to write a library (in C++ or other
language) if it does already exist and is reasonably affordable. Considering
how much debugging and documentation is necessary to make a ground up, home
grown library into a mature product that can be used by the rest of the
team, it just doesn't pay off under most conditions. Sure it is neat to put
a library together that fits like a glove but in the end the "boat anker"
called maintenance is just too much to carry.

Matlab is not only a library of lots and lots of scientific functions, it is
a complete development environment where one can tinker and model and
simulate till the problem is solved with little or nothing of the typical
C++ debugging sessions (hunting pointer problems down for example). Another
important aspect of Matlab is that many folks in the scientific world work
with it which makes code sharing attractive (not impossible to do in C++
but, in my opinion, more difficult).

Matlab is absolutely horrible for GUI applications. I wouldn't even consider
it for "quick demo" tasks but simply compile my functions into a DLL and
call this from a C++ or C# application.

With that said, there are cases whereby one still might consider C++ for a
scientific function library. I can think of three: A) Matlab code isn't fast
enough, B) Matlab code cannot be transported to a DLL or COM object (for
example some of the neural net functions cannot be compiled), or C) Matlab
is too expensive. But even in those cases I would think long and hard
before going C++ entirely...

Hope this helps...

Tuva
Nov 22 '05 #4
Scott McPhillips [MVP] <org-dot-mvps-at-scottmcp> schrieb:
C++ is a general purpose tool that can be used to do anything. For
example, it could be used to create a product like Matlab!
On the other hand, Matlab is reasonably Turing-complete, you could create
a C++-Compiler with Matlab. Or even a complete operating system
(on top of the system it runs on, at least).
Matlab is a special-purpose tool that saves the user lots of time - much
faster development time for problems that it supports, but at the cost
of larger and slower programs.
Not quite true, since Matlab relies on highly optimised and vectorized
code. If you would, say, programm a matrix-triangulation from scratch,
I would bet my ass that Matlab is at least 10 times faster in calcu-
lating the triangulation and the Matlab programmer might be something
like 200 times faster at his goal than the average C++ programmer.
And additionally the script that he has produced will definitely be
_much_ smaller than the C++ code you would need to program for the
same effect.
I often use both Matlab and C++ in the same program. The C++ is added
via a DLL to speed up especially important computations and to provide
interfaces to other programs. The Matlab portion of my product is only
one program - there are ten other (C++) programs in the product that
acquire data, control hardware, and display real-time spectra.


So in your case one could consider Matlab as some kind of specialised
library for your daily C++ work.

Markus
Nov 22 '05 #5

"Lars Christiansen" <la**@tiggerlars.dk> wrote in message
news:43*********************@dread16.news.tele.dk. ..
Hi!

I am a master student in (geo)physics at the University of Copenhagen and
part of a study group on C++ as a scientific programming language.

I, and the other students in the group, have previously used MatLab in
different courses to solve problems, and find it very easy to use.

This has led us to the discussion: When should we use C++ instead of
MatLab? When is C++ superior to MatLab -
When it can do something Matlab can't, or do it more effectively.
and when is it the other way around?
When it can do something C++ can't, or do it more effectively.

The discussion goes on both the time consumption (in programming and
running the program) and capabilities of the two languages (can the one
language do something the other can't).
I'm wondering why such discussion limits possible alternatives
of Matlab to only C++? What about other languages and tools?

I guess you can say that the philosophy behind our discussion is: it does
not help to own some really good tools if you do not know the right
situation to apply them!
Nor does it help to limit the selection to only two.

Please note that I have posted this is both comp.lang.c++ and
comp.soft-sys.matlab.

Thank, Lars.


You are (imo incorrectly) trying to compare the 'general'
with the 'specific'. Matlab is like a 'knife' whereas C++
is more like a 'kitchen'. Matlab can do certain things
very very well, C++ can do many many more things, perhaps
those things for which a specific tool exists, not quite as well.

-Mike
Nov 22 '05 #6
For cases "A" and "C", you might look at O-Matrix,
http://www.omatrix.com/overview.html. A lot of our customers started with
Matlab but then had to consider C/C++ for reasons of cost and speed. For a
lot of our users they were able to achieve those goals but still have an
easy-to-use complete development environment.

"asdf" <Fr****@hotmail.com> wrote in message
news:Tx****************@tornado.socal.rr.com...
Hi Lars,

Good question, one that we have also struggled with from time to time. But
I don't think the answer is all that difficult. From my experience, under
most cercumstances it does not pay off to write a library (in C++ or other
language) if it does already exist and is reasonably affordable.
Considering how much debugging and documentation is necessary to make a
ground up, home grown library into a mature product that can be used by
the rest of the team, it just doesn't pay off under most conditions. Sure
it is neat to put a library together that fits like a glove but in the end
the "boat anker" called maintenance is just too much to carry.

Matlab is not only a library of lots and lots of scientific functions, it
is a complete development environment where one can tinker and model and
simulate till the problem is solved with little or nothing of the typical
C++ debugging sessions (hunting pointer problems down for example).
Another important aspect of Matlab is that many folks in the scientific
world work with it which makes code sharing attractive (not impossible to
do in C++ but, in my opinion, more difficult).

Matlab is absolutely horrible for GUI applications. I wouldn't even
consider it for "quick demo" tasks but simply compile my functions into a
DLL and call this from a C++ or C# application.

With that said, there are cases whereby one still might consider C++ for a
scientific function library. I can think of three: A) Matlab code isn't
fast enough, B) Matlab code cannot be transported to a DLL or COM object
(for example some of the neural net functions cannot be compiled), or C)
Matlab is too expensive. But even in those cases I would think long and
hard before going C++ entirely...

Hope this helps...

Tuva

Nov 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by dataangel | last post: by
3 posts views Thread by Mohammed Smadi | last post: by
9 posts views Thread by Carl | last post: by
4 posts views Thread by Sven Jerzembeck | last post: by
3 posts views Thread by Ajith Menon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.