# Find a parameter to return minimum of the function of several variables

I have two functions $$f_1(n,x)$$ and $$f_2(n,x)$$, and I want them to look similar on the given range $$n\in[1,20]$$. I can only vary the parameter $$x$$.

In other words I have a function $$F(n,x)=f_1(n,x)-f_2(n,x)$$ and want to find $$x$$ returning its minimum along the range $$n\in[1,20]$$ ($$\sum_{n=1}^{20}F(n,x)$$).

Does Mathematica have any routines to do so (seems it relates to Least squares) ? What I need to do to fit a function by another one on the given range $$n\in[1,20]$$ varying only x ? I tried to find the solution, but what I found so far (Minimize and MinValue) was for a function of a single variable. I am sure what I am looking for is trivial, and there is such a function in Mathematica, but I am stacked now.

Expressions are the following (in fact they are way complicated):

f1=1./((1 - E^(-x n))^(1/6) n^(1/3));
f2=1./((1 - E^(-x n))^(1/5) n^(1/2));


I may introduce the following algorithm, which interprets and may explain the method of minimization:

% Define the functions
\begin{verbatim}
f1[n_, x_] := 1./((1 - E^(-x n))^(1/6) n^(1/3));
f2[n_, x_] := 1./((1 - E^(-x n))^(1/5) n^(1/2));

% Define the objective function
objective[x_] := Sum[Abs[f1[n, x] - f2[n, x]], {n, 1, 20}];

% Find the value of x that minimizes the objective function
result = NMinimize[objective[x], x]

% Display the result
result
\end{verbatim}


Here is the Mathematica code which interprets the above algorithm:

(* Define the functions *)
f1[n_, x_] := 1./((1 - E^(-x n))^(1/6) n^(1/3));
f2[n_, x_] := 1./((1 - E^(-x n))^(1/5) n^(1/2));

(* Define the objective function *)
objective[x_] := Sum[Abs[f1[n, x] - f2[n, x]], {n, 1, 20}];

(* Find the value of x that minimizes the objective function *)
result = NMinimize[objective[x], x]

(* Display the result *)
result


The problem is unbounded (it's always important to check boundaries in optimization) so a global minimum exists in the limit as $$x \rightarrow -\infty$$:

f1 = 1./((1 - E^(-x  n))^(1/6)  n^(1/3));
f2 = 1./((1 - E^(-x  n))^(1/5)  n^(1/2));

diff = f1 - f2;

Assuming[1 <= n <= 20, Limit[diff, x -> -Infinity]]

(*0*)



If this was just given as an example however, one thing we can do is use the fact that $z ~ z^* = |z|^2$ to give us our squared error and minimize:

diffSq = diff * Conjugate[diff];
objective = Sum[diffSq, {n, 20}];
NMinimize[objective, x]

(*{9.02118*10^-40, {x -> -269.711}}*)