473,386 Members | 1,654 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,386 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 22220
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.