Shortest distance between two general curves using matlab

To answer, I assume $F(x)$ and $G(x)$ are continuous in $I \in \mathbb{R}, I = [a,b]$. For simplicity, let $F(x)=f, G(x) = g, H(x) = h = f-g$. By symmetry I can assume $f \ge g$. Now consider the function $h(x)$:

  • if $\exists x | h(x) = 0$, it means that there is a point $x$ such that $f(x) = g(x) \Rightarrow ||f(x) - g(x)|| = 0$ and so the minimum shortest distance between $f$ and $g$ is 0
  • else, find the minimum value of $h$ (by letting $h'=0$): let's call the minimum $m$. Let $P$ be the point found intersecating $f$ and the normal (i.e the tangent to the tangent to the curve) to $g$, and $N$ vice-versa (please, take a look at the image below). You need to fix a point $a$ on $f | P \le a \le f(m)$ and a point $b$ on $g| g(m) \le b \le N$, then the shortest distance is $\min[||a-b||]$. enter image description here

There are several ways to solve this kind of problem: the choice of methods depends on the details of the two functions/curves. I will assume here you mean the usual definition of distance between two curves, where the given line segment may not be vertical.

1) As you suggest, parameterize the two curves, find the distance function between two points--one on each curve--and minimize the distance function. As you write, this will be a function of two independent variables, so you need to use multivariable calculus.

2) Use Lagrange multipliers. This will involve (I think) four independent variables: $x$, $y$, and one for each curve. This is even more multivariable.

3) Given common assumptions, the line segment of minimal length between the functions is perpendicular to the tangent line at each function. You could then parameterize the normal lines for each function and find which lines are common to both curves. You may get more than one, but there are probably finitely many, so choose the normal lines that give the smallest distance.

4) There are also combination strategies, such as finding the normal lines to one curve, finding the intersection of each line with the other curve, finding the resulting distance, and minimizing that expression. This strategy avoids multiple variables.