Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Common tangent
Date: Wed, 28 Nov 2007 10:59:53 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 87
Message-ID: <fijhn9$bfi$1@fred.mathworks.com>
References: <fihu0m$quf$1@fred.mathworks.com> <fiivds$lqs$1@fred.mathworks.com> <fij6n6$9h7$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1196247593 11762 172.30.248.38 (28 Nov 2007 10:59:53 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 28 Nov 2007 10:59:53 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:439772


"Bruno Luong" <brunoluong@yahoo.com> wrote in message 
<fij6n6$9h7$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
> wrote in message <fiivds$lqs$1@fred.mathworks.com>...
> > 
> >   As John intimated, if you only possess f and g in the
> form of discrete 
> > vectors, you cannot expect to find precise solutions to
> the problem but would 
> > have to settle for solutions to finite difference
> approximations.
> 
> After formalization, this problem is equivalent to be
> finding two abscissas so that two coefficients that describe
> the tangent at respective points are matched. This is like
> finding an intersection of two parametric curves in R^2
> (each axis of the plane corresponds to a coefficient of the
> tangent).
> 
> Well, first the derivative must be computed one way or
> another, finite difference would provide the derivative, but
> only at discrete points.
> 
> IMHO the "tricky" part is to be able to calculate the
> derivative - not only at discrete point - but at any point.
> The same applied for the input functions. And it's better if
> one can provide a continuous functions and its derivatives,
> so that the two parametric curves are continuous, and they
> intersection can be solved.
> 
> If one can parametrize the input functions by cubic-spline,
> its derivative is continuous (even C^1 IIRC). Both are
> piecewise polynomials.
> 
> Next, it is just a question of solving it. There is
> certainly a little bit of work, but I can't see any major
> difficulty to implement an algorithm to solve the problem.

Yes. It will either be a problem of comparing all
pairs of tangent lines, taking the two which are
"closest" under some metric, or an optimization,
to find the two points x1 and x2, one for each
continuous curve. Fminsearch will probably be
adequate for the optimization task, since this is
only a two variable problem. Of course, fsolve
will also suffice. You can formulate it for either
solver.

In the latter case, you will need continuous
functions, so it seems silly to discretize the
problem with vectors of points, which then
need to be interpolated by splines. Keep them
as functions to be evaluated if at all possible.
Of course, if they are indeed functions, then
you need to differentiate them accurately. You
might need to use a tool like my derivest, from
the file exchange. So perhaps a pair of spline
interpolants might be a good choice, since they
will be easy and efficient to interpolate.

Also in the event of the optimization, recognize
that while an optimizer can solve the problem,
this may well have multiple local minima, or it
may have no true solution at all. You will need
good starting values, or you will need to start
off the optimizer at multiple points, taking the
best overall solution.

Finally, in either event, you will need to choose
some metric to compare two lines. How will you
define two lines as being the same, since in an
optimization, the two lines will generally be
only approximately the same and you need to
minimize the difference? I'd imagine that a
reasonable metric is the integral of the square
of the difference of the two lines, integrated
over the domain of the interval where the
functions will be compared. Knowing the slopes
and intercepts of the two lines, this objective
should be computable directly using a little
algebra.

So while Bruno is correct that it is doable, it
might take a bit of work to do it well.

John