structure input for FindRoots

Functions to be solved by FindRoots can be passed a parameter wave, but for some calculations I would like to pass a large number of parameters that are best represented in a multidimensional form. I think that the parameter wave must be 1D. It would be great if we could use a structure to pass multiple kinds of data to the function.

In my case, the calculation of input parameters is costly, but only needs to be done once for a given call to findroots IF I have a way to pass those parameters, otherwise they must be recalculated on every iteration. I think the situation is the same for the optimize operation.

Could it be done?

Anything can be done :)

The addition of structure fit functions was a big effort- dealing with structures is fairly complicate internally. So its one of those things where I need to balance effort against outcome. In this case, it's a relatively rarely used operation and an enhancement that not many need or have the expertise to use.

I know it's kludgey and goes against the recommendations of not using globals...

How about creating a data folder with the info you need, and storing a pointer to it in either DF wave or as a global string? The DF wave would give you better performance in the lookup required to access the data folder.

In reply to by johnweeks

That's more or less what I have done.

I use one parameter in the parameter wave as a flag to indicate that global parameters are available, and the locations are simply hardwired into the function.

Looks like I will have to stick with that method. I'm managing to multithread at the same time, I think safely, and performance is OK.

That sounds fine. Using Multithread inside your object function should be fine, and FindRoots itself is threadsafe, so you can run multiple instances in threads. FindRoots is not threaded internally.

That all applies to Optimize as well.