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

MathGroup Archive 2011

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

Search the Archive

Curve fit for piecewise - Lazy evaluation (Defer / Hold?) on constraint passed to Minimize[]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119454] Curve fit for piecewise - Lazy evaluation (Defer / Hold?) on constraint passed to Minimize[]?
  • From: Eric Cousineau <eacousineau at gmail.com>
  • Date: Sat, 4 Jun 2011 06:21:52 -0400 (EDT)

Is there to defer / hold evaluation for a constraint passed to Minimize[]?

I'm wondering because I want to ensure that a particular point on the curve fits as closely as possible to the given data, i.e., give it more weight at that point.

Example: (sorry for some of the hackish things, coming to Mathematica from another system)
param = {x0, a, b, c, ...};
xflat = ...
yflat = ...
x0index := Position[xflat, Nearest[xflat, x0][[1]]][[1]];
y0 := yflat[[x0index]][[1]] &;
funcs = {{f[x], x < x0}, {g[x], x >= x0}};
model = Piecewise[funcs];
constraint := y0 == funcs[[1,1]] == funcs[[2,1]] /. x->x0;
(*Not sure how to do lazy*)
results = Minimize[{model, constraint}, param];

This code works without involving the y0 expression. Once that's involved, I get the error:
NMinimize::bcons: The following constraints are not valid: ... Constraints should be equalities, inequalities, or domain specifications involving the variables.

I've tried apply Defer[] and Hold[] just for kicks and giggles, but it didn't work.


  • Prev by Date: Re: Dt@x@1
  • Next by Date: Re: ContourPlot ColorFunction Question
  • Previous by thread: Re: problems with strings mixed into notebook cells
  • Next by thread: Listbox type progress display?