[Date Index] [Thread Index] [Author Index]
Re: Maximizing function which defines a routine
On 1/14/09 at 5:32 AM, mryan1 at uoregon.edu (Mark) wrote: >(Apologies up front for my utter lack of programming ability--the >only language Ive ever really programmed in is Basic and I havent >even done much of that) >I have a function "G" in two arguments (x,y) which uses a loop (Im >using label/goto for this loop if that gives any idea of my >programming abilities) to alter the values of three "state" >variables (a,b,c). The output of this function is to store the final >values of these three variables a,b,c, (globally). >Is it possible in Mathematica to use Maximize or NMaximize on this >function, in order to, for example, find the "x" which maximizes "a" >(given y)? The only answer possible to your question is that it depends on details of the function you have not posted. There is nothing about using loops as part of the function definition automatically prevents NMaximize from being successful. If you provide details of your function (preferably the Mathematica code that implements your function) I or another poster quite likely can help you. Now having said the above, I will also note efficient programming in Mathematica is quite different than programming in Basic. I do not believe there are any programs in Mathematica that would be considered efficient programs that use a label/goto construct. In fact, most efficient Mathematica programs do not use explicit loops. Additionally, using a loop to modify global variables is probably a bad idea. Usually, this causes problems when the same variables are used else where in a notebook. If you plan to use Mathematica quite a bit and want to become proficient in writing Mathematica code, there are a number of books that will give you a good place to start. For example, there are Maeder's books Programming in Mathematica and The Mathematica Programmer. I am sure others responding to your post can provide other recommendations.