473,769 Members | 6,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 22260
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**@tiggerlar s.dk> wrote in message
news:43******** *************@d read16.news.tel e.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....peco s pe***@cminet.ne t
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**@tiggerlar s.dk> wrote in message
news:43******** *************@d read16.news.tel e.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******** ********@tornad o.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
16929
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 tried: - Image.show() which is nice but slow and I don't seem to be able to either close the window nor draw again to the same window, so I end up with 100 pictures on the screen... - scipy.xplt.imagesc() and scipy.plt.imagesc() crash
4
2762
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 prefer to do the bulk of the project in python because I'm familiar with pygame (for the visuals) but I already have a lot of AI code written in Matlab. I'd like to be able to call Matlab code from within python. I'm not sure this is possible. My...
3
4005
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 by feeding the args from a script. I know this is probably more suitable to a matlab group but any ideas will be appreciated.
9
5297
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 rather restricted facilities for doing other things than standard mathematical work. Does anyone know of good techniques (or readily available software) for achieving a cross-language support between Python and Matlab? Carl
4
2032
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 answering in advance Sven
8
2122
by: Allen | last post by:
Does anyone agree with me? If you have used Matlab, welcome to discuss it.
3
27248
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 functions are available in the MATLAB SP toolbox) These functions require input waveforms X and Y, which is nothing but two array of samples (datatype=double).
4
13752
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 from Python! Any suggestions would be appriciated!
14
3146
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 parameters such as t, l1, l2, l3, etc. are scalars... But u is a vector.
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.