C++ vs. Matlab

Discussion in 'C++' started by Lars Christiansen, Nov 20, 2005.

  1. 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.
     
    Lars Christiansen, Nov 20, 2005
    #1
    1. Advertising

  2. 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]
     
    Scott McPhillips [MVP], Nov 20, 2005
    #2
    1. Advertising

  3. "Lars Christiansen" <> wrote in message
    news:4380959f$0$208$...
    > 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
     
    Bill Shortall, Nov 20, 2005
    #3
  4. Lars Christiansen

    asdf Guest

    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
     
    asdf, Nov 20, 2005
    #4
  5. 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
     
    Markus Becker, Nov 20, 2005
    #5
  6. Lars Christiansen

    Mike Wahler Guest

    "Lars Christiansen" <> wrote in message
    news:4380959f$0$208$...
    > 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
     
    Mike Wahler, Nov 21, 2005
    #6
  7. 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" <> wrote in message
    news:Tx3gf.6484$...
    > 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
    >
     
    Harmonic Software, Nov 21, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. moe
    Replies:
    1
    Views:
    2,304
    Tom Hawkins
    Oct 26, 2003
  2. Ouadid
    Replies:
    7
    Views:
    10,272
    Jim Wu
    Dec 18, 2003
  3. Juan Carlos Allica
    Replies:
    0
    Views:
    1,101
    Juan Carlos Allica
    Jul 15, 2005
  4. siki
    Replies:
    0
    Views:
    975
  5. Luna Moon
    Replies:
    16
    Views:
    1,353
    Giovanni Gherdovich
    Aug 8, 2008
Loading...

Share This Page