# Help to Build Proper Expression for Complicated FuncFit Case

jjweimer

Fri, 07/21/2017 - 12:22 pm

I have a sequence of functions F1, F2 ... FN that are summed to give a total function FT. Each function Fj can have different types (e.g. a full form or an approximation). Each form of each function has its own input parameters pjk. I have a control panel designed to allow a user to select what functions to sum (i.e. in some cases Fj = 0), what form of a function to use when it is to be summed, and what values of parameters to use in the function. IOW, I have a control panel that allows a user to show how various cases appear in a graph depending on expectations (which equation is / is not added to the set), approximations (type of function), and system conditions (input parameters).

I have no problems so far.

I add to this mix the option to generate "noise" on the FT using the gnoise(...) function. The result is a model noisy curve overlaying a theoretical true curve.

I still have no problems to here.

Now, I want to reverse one part of this process. I have one specific input parameter, call it A, that is fundamental to the entire system. I want to fit the model noisy data with the theoretical equations to obtain A ± \Delta A. IOW, I want to find out, for a given set of expectations + approximations + system conditions + noise what we could expect to obtain in the confidence in A.

For those still with me, this is called uncertainty budget analysis. I have a submitted paper on it from the theoretical side. I am now attacking the simulation/modeling side.

At the moment, I have only two Fj functions that are of immediate concern. I am in fact doing the test with only one to obtain the proof of concept. My problem is to determine how I can design a call to the FuncFit operation that will allow me to do what I need immediately (fit any type of F1 pre-selected by the user) and also not lock me out of growing the model to adding other Fj terms.

Here is an example of the function that generates the one Fj function that I have under design ...

//structure for vdWForces

// ww[0] - A

Structure vdWForces

wave ww

variable xx

variable type

variable Rs

variable lambdac

endStructure

// coefficients for vdW forces

// 0 - A; type; Rs; lambdac

Function generate_fcvdW(fs,z)

STRUCT vdWForces &fs

variable z

// local variables

variable rtn

// returns at boundaries

if (z <= 0)

return NaN

endif

fs.xx = z

// calculate

switch(fs.type)

case 0: // unretarded short distance

rtn = fvdWua(fs)

break

case 1: // unretarded full

rtn = fvdWuf(fs)

break

case 2: // retarded

rtn = fvdWrs(fs)

break

endswitch

return rtn

end

// ww[0] - A

Structure vdWForces

wave ww

variable xx

variable type

variable Rs

variable lambdac

endStructure

// coefficients for vdW forces

// 0 - A; type; Rs; lambdac

Function generate_fcvdW(fs,z)

STRUCT vdWForces &fs

variable z

// local variables

variable rtn

// returns at boundaries

if (z <= 0)

return NaN

endif

fs.xx = z

// calculate

switch(fs.type)

case 0: // unretarded short distance

rtn = fvdWua(fs)

break

case 1: // unretarded full

rtn = fvdWuf(fs)

break

case 2: // retarded

rtn = fvdWrs(fs)

break

endswitch

return rtn

end

I am hoping to use two parts of FuncFit. First, I hope to use the string expression form to sum functions

`FuncFit {string=...} ...`

. Secondly, I am hoping to stay with structure functions. But ... now the problem. First, I see that string expressions may only work with coefficient waves, not structure functions. OK, I tried that. My problem is, when I feed four parameters to the coefficient wave and only want ONE of them to vary (so I set holdstring = "1011"), I get singular matrix issues (e.g. no dependence on coef[0] or coef[3]).Where should I go next? I am stubbornly reluctant to think that I should hard code this and then have to rebuild the hard code for each new case in the future. But, perhaps that is the best option here???

For those so interested, this is a van der Waals force term expression between two macroscopic bodies. Eventually this will end up with repulsive, capacitance, double-layer, and viscous fluid forces. It is heading toward models of data from force-distance curves obtained in atomic force microscopy or the surface force apparatus. Contact me off-line when you might have some interest in the details.

Recommendations would be appreciated.

TIA!

July 22, 2017 at 06:06 am - Permalink

It was probably the Friday-night sangria yesterday that helped me resolve my initial stubbornness. :-)

--

J. J. Weimer

Chemistry / Chemical & Materials Engineering, UAH

July 22, 2017 at 11:50 am - Permalink

John Weeks

WaveMetrics, Inc.

support@wavemetrics.com

July 24, 2017 at 09:10 am - Permalink

My test was with just one function in the

`string={...}`

call. Everything worked EXCEPT that I got singular matrix issues. By the time I was done thinking about the problem in greater breadth, I realized that I only have one parameter that I need as a coefficient. It really makes no sense to do anything other than a hard-coded fitting function that uses a coeff wave rather than a structure fit function. The one downside is, I have to pass fixed parameters in to the function. The hard parameters pjk are pulled from the panel input. I know how to pass the parameters as globals or through a structure initialization routine. The few upsides are that I am able to put the core functions Fj in to structure format (i.e. as FuncFit functions) and "hide" them in independent modules as static. I have a top-level function (non-static) that is the entry point to the independent module. That top-level function has takes the call`imname#forceeqn(ww,xx)`

. The coeff wave ww has only one parameter (the A parameter that I am reverse analyzing).It all works rather nicely now!

--

J. J. Weimer

Chemistry / Chemical & Materials Engineering, UAH

July 24, 2017 at 05:15 pm - Permalink