0
$\begingroup$

I need a nonlinear least squares function $f: \mathbb{R} \rightarrow \mathbb{R}$ which has multiple minima in order to plot it and test some convergence methods using it.

Please note:

The function must be of the form $f = \frac{1}{2} r^2$ where $r: \mathbb{R} \rightarrow \mathbb{R}$

I do not want the smallest minimum to be where $f(x) = 0$, it must be a non zero residual problem.

$f(x)$ can not take negative values, but $x$ can be negative.

Thanks

$\endgroup$
0
$\begingroup$

Take e.g. $r(x) = (x-a)^2(x-b)^2 + 1$. It will have two minima (at $x=a$ and $x=b$), and will never be zero (thanks to $+1$ in the end), implying $f$ will never be zero (in particular $f(x) \neq 0$ for the minima). Thus, it satisfies your conditions.

Live on Desmos


If you need the function to have different values at different minima, or if you want more than two minima, you can try this approach. Let $x = a_1, \dots, a_n$ be our minima, and $c_1, \dots, c_n \in (0, 1)$ and $d_1, \dots, d_n$ some constants. Define

$$r_i(x) = 1 - (1-c_i)exp(-d_i(x-a_i)^2)$$

$exp(-d_i(x-a_i)^2)$ defines a "bump" with maximum at $a_i$, and $d_i$ controls it's flatness. $r_i$ is this same bump, reversed and scaled so that it takes value $c_i$ at $x=a_i$ and takes the value of $1$ when $x$ is far from $a_i$.

Now, take the product of the $r_i$:

$$r(x) = r_1(x) \cdot r_2(x) \cdots r_n(x)$$

Live on Desmos

$\endgroup$
  • $\begingroup$ Thanks for this, that works but at the moment the two minima give me the same value for $f(x)$. I should have added that I would ideally like the minima to be different so $f(a) \neq f(b)$. Any idea? Thanks $\endgroup$ – M6126 Oct 11 '18 at 15:26
  • $\begingroup$ @M6126 I've updated the post. $\endgroup$ – lisyarus Oct 11 '18 at 16:05
  • $\begingroup$ That's amazing, thanks very much! $\endgroup$ – M6126 Oct 12 '18 at 8:20

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.