# Find the linear combination of two functions to fit to a third

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.

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}

• Hard to argue otherwise, it is indeed the error, and not the total difference which needed to be minimised. – user19218 Jan 4 '16 at 19:41
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}] • 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. – user19218 Jan 4 '16 at 14:01