473,231 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

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 22211
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mathias | last post by:
Dear NG, I currently ty to switch from matlab to python/scipy but have a lot of trouble with images. What I need is a function for subsequently displaying a number of 2D-matrices as an image. I...
4
by: dataangel | last post by:
I'm a student who's considering doing a project for a Machine Learning class on pathing (bots learning to run through a maze). The language primarily used by the class has been Matlab. I would...
3
by: Mohammed Smadi | last post by:
Hi; Does anyone know if we can call matlab for a python or bash script while feeding the matlab script some command line arguments? I have an interactive matlab script which i want to automate...
9
by: Carl | last post by:
I am desperately looking for a way to call Python from Matlab. I have become used to Python's rich syntax and large number of libraries, and feel ridiculously clumsy being stuck with Matlab's...
4
by: Sven Jerzembeck | last post by:
Hello guys, is there any possibiliy using Phython code in Matlab. I couldnt find any helpful stuff. Its not graphical stuff I am doing just calculations with arrays and strings. Thanks for ...
8
by: Allen | last post by:
Does anyone agree with me? If you have used Matlab, welcome to discuss it.
3
by: Ajith Menon | last post by:
Do any body know how to use the functions available in the MATLAB using C#? ( To be specific, functions COHERE used to find Coherence and TFE to calculate Transfer function are needed. These...
4
by: itcecsa | last post by:
Hi, I am implementing a small Python project, what I am going to do is to open Matlab and run some M-files, and get some output from Matlab command prompt. I have no idea how to open Matlab...
14
by: Luna Moon | last post by:
Dear all, Can C++/STL/Boost do the vectorized calculation as those in Matlab? For example, in the following code, what I really want to do is to send in a vector of u's. All other...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.