0
$\begingroup$

I have been trying to solve a simple enough problem, but I can't seem to find the proper method. The problem is given as,

Find 0 < x < 1 for which, h(t) $\approx$ (1-x) f(t)+x g(t), where is given that without loss of generality, f(t) > h(t), g(t) < h(t) for all t > 0. And all functions are given, and are (roughly) of the same form.

The one way I came up with was, creating a data set of points { t , h(t) }, and then using the NonlinearModelFit function. But I am hesitant because this would mean information loss, furthermore, this will be part of a much larger code and I feel there should be a more efficient method.

Any help would be greatly appreciated.

$\endgroup$
2
$\begingroup$

If I understand the question, I would think you want to minimize the error:

h[t_] := Exp[-t]
f[t_] := Exp[-t/2]
g[t_] := Exp[-3 t]
Last@Minimize[Integrate[(h[t] - ((1 - x) f[t] + x g[t]))^2,
   {t, 0, \[Infinity]}], x]

{x -> 1/2}

note your numerical approach gives essentially this result:

NonlinearModelFit[Table[ {t, N@h[t]}, {t, 0, 1000, .1}] ,
   x g[t] + (1 - x) f[t] , x , t]["BestFitParameters"]

{x -> 0.500011}

$\endgroup$
  • $\begingroup$ Hard to argue otherwise, it is indeed the error, and not the total difference which needed to be minimised. $\endgroup$ – user19218 Jan 4 '16 at 19:41
4
$\begingroup$
h[t_] := Exp[-t]
f[t_] := Exp[-t/2]
g[t_] := Exp[-3 t]

xOpt = x /. FindRoot[Integrate[h[t] - ((1 - x) f[t] + x g[t]), {t, 0, ∞}], {x, 0.5}]
0.6
Plot[{h[t], (1 - xOpt) f[t] + xOpt g[t]}, {t, 0, 10}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ This is definitely the more elegant solution, I was thinking in circles and it never crossed my mind to use the integrants. Thank you! For good measure I timed the calculations and it was 8x faster on the interval I was calculating. $\endgroup$ – user19218 Jan 4 '16 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.