<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/157466</link>
    <title>MATLAB Central Newsreader - Passing constants to optimization functions</title>
    <description>Feed for thread: Passing constants to optimization functions</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>Wed, 10 Oct 2007 15:19:17 -0400</pubDate>
      <title>Passing constants to optimization functions</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/157466#396014</link>
      <author>David Doria</author>
      <description>I am trying to use lsqnonlin(), but my user defined function&lt;br&gt;
needs to know a couple of constants.  The lsqnonlin expects&lt;br&gt;
my function to only accept one parameter (the one being&lt;br&gt;
optimized).  Is there a better way to &quot;pass&quot; these constants&lt;br&gt;
besides making them global?&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
&lt;br&gt;
David</description>
    </item>
    <item>
      <pubDate>Wed, 10 Oct 2007 15:36:26 -0400</pubDate>
      <title>Re: Passing constants to optimization functions</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/157466#396020</link>
      <author>John D'Errico</author>
      <description>&quot;David Doria&quot; &amp;lt;daviddoria@gmail.com&amp;gt; wrote in message &amp;lt;feiqhl$7nd&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I am trying to use lsqnonlin(), but my user defined function&lt;br&gt;
&amp;gt; needs to know a couple of constants.  The lsqnonlin expects&lt;br&gt;
&amp;gt; my function to only accept one parameter (the one being&lt;br&gt;
&amp;gt; optimized).  Is there a better way to &quot;pass&quot; these constants&lt;br&gt;
&amp;gt; besides making them global?&lt;br&gt;
&lt;br&gt;
Use an anonymous function.&lt;br&gt;
&lt;br&gt;
a = 2;&lt;br&gt;
f = @(x) (x-a).^2;&lt;br&gt;
&lt;br&gt;
Obviously, the minimum occurs at x = a = 2.&lt;br&gt;
Can we find it?&lt;br&gt;
&lt;br&gt;
x = fminsearch(f,0)&lt;br&gt;
x =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John</description>
    </item>
  </channel>
</rss>

