<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165594</link>
    <title>MATLAB Central Newsreader - Minimize a c++ function with matlab</title>
    <description>Feed for thread: Minimize a c++ function with matlab</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 13 Mar 2008 12:04:15 -0400</pubDate>
      <title>Minimize a c++ function with matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165594#420661</link>
      <author>David Doria</author>
      <description>Recently I've been looking into the matlab engine for&lt;br&gt;
calling matlab from c++. I would like to utilize fminunc()&lt;br&gt;
from a c++ program.  Say I have a c++ function:&lt;br&gt;
&lt;br&gt;
int MyFunc(int Param)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;return pow(Param,2);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
Is there anyway to pass this function to fminunc()?? Seems&lt;br&gt;
like a reasonable thing to want to do, but from what I know&lt;br&gt;
about the engine I have no idea how to approach it.&lt;br&gt;
&lt;br&gt;
Any tips would be great!&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
&lt;br&gt;
David</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 17:48:02 -0400</pubDate>
      <title>Re: Minimize a c++ function with matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165594#420751</link>
      <author>James Tursa</author>
      <description>&quot;David Doria&quot; &amp;lt;daviddoria@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;frb57u$die$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Recently I've been looking into the matlab engine for&lt;br&gt;
&amp;gt; calling matlab from c++. I would like to utilize fminunc&lt;br&gt;
()&lt;br&gt;
&amp;gt; from a c++ program.  Say I have a c++ function:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; int MyFunc(int Param)&lt;br&gt;
&amp;gt; {&lt;br&gt;
&amp;gt;   return pow(Param,2);&lt;br&gt;
&amp;gt; }&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is there anyway to pass this function to fminunc()?? &lt;br&gt;
Seems&lt;br&gt;
&amp;gt; like a reasonable thing to want to do, but from what I &lt;br&gt;
know&lt;br&gt;
&amp;gt; about the engine I have no idea how to approach it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any tips would be great!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; David&lt;br&gt;
&lt;br&gt;
One approach would be to create a mex function that takes &lt;br&gt;
your desired mxArray input (i.e., prhs[0]), calls mxGetData&lt;br&gt;
(prhs[0]) to get the pointer to the data, pass that &lt;br&gt;
pointer to your C++ MyFunc function, and put the result of &lt;br&gt;
the MyFunc call into a new mxArray created by you in plhs&lt;br&gt;
[0]. This mex function could then be called by the MATLAB &lt;br&gt;
engine, and in particular the function fminunc(), where &lt;br&gt;
the input function handle fun is a handle to the mex &lt;br&gt;
function. You could invoke it from an engine application &lt;br&gt;
through judicious use of engPutVariable, engEvalString, &lt;br&gt;
and engGetVariable calls.&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
  </channel>
</rss>

