Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mathematica in conjunction with outside program; NMinimize fails.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98954] Re: Mathematica in conjunction with outside program; NMinimize fails.
  • From: dh <dh at metrohm.com>
  • Date: Wed, 22 Apr 2009 05:14:56 -0400 (EDT)
  • References: <gsivfv$9dj$1@smc.vnet.net>


Hi Andreas,

functions without the attribute HoldFirst/HoldAll do evaluate their 

arguments before the function call.

Therefore, mma tries to evaluate SingleModelRun[ myvalue ] with the 

symbolic value "myvalue ". You must prevent this by defining:

SingleModelRun[ parametervalue_?NumericQ ] :=...

Daniel





Andreas Pape wrote:

> Hello mathgroup.  I am using Mathematica in conjunction with an  

> outside program (Netlogo is the program.)  In a nutshell, my error is  

> the following: I can call the outside program with a numeric value  

> successfully, and Plot can call the outside program as one would  

> expect.  However, NMinimize calls the outside program with the  

> variable name, not a value, so it fails.  In short, I need to force  

> NMinimize to pass a numeric value to the objective function, not a  

> variable name.

> 

> More details:

> 

> I have the following functions defined in Mathematica:

> 

> 	SingleModelRun[ parametervalue_ ] := ....(definition irrelevant)

> 		This function (successfully) runs the outside program, setting a  

> parameter equal to "parametervalue" (which is some number when I call  

> the function).  It returns a value from the model.

> 

> 	Plot[ SingleModelRun[ x ], {x , 0, 1} ]

> 		Does what you expect: runs SingleModelRun for parameter values 0  

> through 1, and plots the resulting return value each time.

> 

> 	NMinimize[ - SingleModelRun[ myvalue ], {myvalue} ]

> 		Does not work.  Returns the following error:

> 

> 		NetLogo`Private`NetLogo::"compilerException" : "Nothing named  

> MYVALUE has been defined"

> 

> 	(Note: NetLogo is the name of the outside program.)

> 

> Which means that, oddly, NMinimize passes the *variable name*  

> (myvalue) instead of the *variable value* to the function  

> SingleModelRun; otherwise, there is no way the outside program would  

> be aware of the variable name.

> 

> 	Is there a way to force Mathematica to evaluate the function with a  

> numeric value, not the variable name?  (I thought that's what "N" in  

> "NMinimize" meant, but apparently not.)

> 	

> 	In case you were wondering, this fails in an identical way with:  

> NMaximize, FindMaximum, FindMimimum, etc.

> 

> 	Thank you.

> 

> 			Sincerely,

> 			Andreas Duus Pape

> 

> 




  • Prev by Date: Re: Looking for more Mathematica online user groups/forums
  • Next by Date: Re: Help with a possible bug
  • Previous by thread: Re: Mathematica in conjunction with outside program; NMinimize fails.
  • Next by thread: Re: Mathematica in conjunction with outside program; NMinimize fails.