Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Call a MEX function from Matlab Engine?
Date: Sat, 15 Mar 2008 22:15:07 +0000 (UTC)
Organization: Boeing
Lines: 59
Message-ID: <frhhpb$8f5$1@fred.mathworks.com>
References: <frc4bp$ipi$1@fred.mathworks.com> <frc7ir$s19$1@fred.mathworks.com> <frccfq$l2f$1@fred.mathworks.com> <frch5p$bdj$1@fred.mathworks.com> <frdvs6$lim$1@fred.mathworks.com> <fre31g$bk1$1@fred.mathworks.com> <fre6af$jpp$1@fred.mathworks.com> <frftgn$630$1@fred.mathworks.com> <frgbgs$hn8$1@fred.mathworks.com> <frh2lf$i59$1@fred.mathworks.com> <frh3ul$qi1$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205619307 8677 172.30.248.38 (15 Mar 2008 22:15:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 15 Mar 2008 22:15:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:457433



"David Doria" <daviddoria@gmail.com> wrote in message
<frh3ul$qi1$1@fred.mathworks.com>...
> Sorry I was not clear.  The actual c++ function I want to
> minimze is
> 
> double CostFunction();

I don't get it. What is the independent variable here? Cost
function based on what independent input(s)? How were you
thinking of calling fminunc or fmincon?

> CostFunction() calls many other functions such as
> DistanceToPoint(), DistanceToPolygon() blah blah and also
> records alot of things that are globals for the sake of the
> OpenGL portion of my program. Also, these Distance()
> functions that I mention rely on alot of classes that I
> wrote such as 
> class Polygon
> class Edge
> etc
> 
> I don't see how I can mex call of those things.  Maybe I
> simply can't do this.

Compiling is not the issue, really. You can use all of your
classes and custom functions in a mex routine. Think of it
this way: A mex routine is a dll with no console i/o
capability that hooks directly into MATLAB as a callable
function, whereas an engine application is a stand-alone
program with full console i/o capability that communicates
with a separate MATLAB process via (I think) a COM link. But
in both cases you still have full access to everything that
a C++ compiler can compile.

Sounds like you need your mex routine to communicate data
with your engine application (i.e., the globals you mention
and maybe other things). Is this correct? If so, then that
is going to be a problem. We can probably set up something
to transmit fundamental types back & forth (int, double,
etc.), but if you need to transmit class variables back &
forth then that would be a huge issue and probably not worth
the effort.

> I found a package called GSL (GNU
> scientific library) that has some unconstrained
> minimization, and also a package for GSL called OOL (Open
> Optimization Library) that contains some basic constrained
> minimization functions.  These seem to work fine, but I
> would have like to confirm their results with the matlab
> fminunc() and fmincon() functions.

If you can set your problem up so that your cost function
fits into something fminunc and fmincon can handle, then
maybe it can be done. But if you have a lot of global class
variable etc that your cost function depends on, then it
will probably be too much work.

James Tursa