How can I find a tangent line to an unknown point on a curve?

I have got an optimisation problem, where I want to find the capital market line on my efficient frontier.
I want to find the tangent to the curve from a given value on the y-axis. I have literally no clue where to start this. My graph looks something like this:
x=-100:0.01:100;
f=(3-x).^2+5;
plot(f,x)
axis([0 10 -10 10])
How can I find the tangent from (0,0)?
Thanks,
Zeeshan

Answers (1)

Find a tangent line from a given point (x0,y0) to the curve
y = (3-x).^2+5
is a matter of solving two simultaneous equations in two unknowns. Let (x,y) be the point of tangency on the curve. Then we have
(y-y0)/(x-x0) = 2*x-6 (Slope of line equals derivative of curve at x)
y = (3-x)^2+5 (The point (x,y) lies on curve)
These two equations lead to a simple quadratic equation in x which has either two solutions, one solution, or none, depending on (x0,y0), and therefore a similar number of possible tangent lines.
For a general curve, finding the tangent line is also done by finding the solutions to two equations in two unknowns found in a similar manner as above. However, it might require the use of 'fzero' or even 'fsolve' to find the solutions, depending on the nature of the curve's equation.

5 Comments

Ooops. I think I may have not explained the question properly. The graph 'looks' similar, but the equation of the line is given by various matrix operations, which is why I can't algebraically solve this. I just used the given function as a visual aide.
Any ideas?
You spoke of a "tangent" line, but apparently tangency is not what determines the line. If you want a valid answer to your request, it would be necessary to explain, even if in simple terms, just what it is that does determine the line.
You should still be able to use Rogers solution since you can do the algebra ignoring the matrix operations (which really is just sticking a whole array into an algebraic function).
However if you really wanted to do this analytically for a curve you don't have a descriptive equation for, you could find the slope through some application of the diff function, and then solve algebraically from there, using the (x,y) coordinates of each point to find the zeros for the tangent line.
By tangent, I meant the curve is touched by a straight line at one point only. So one of the points of the straight line I assign to be on the y-axis (the origin) and the another point is the tangent.
And please explain how I can still use Roger's solution. I am under the impression that Roger's solution requires me to know the derivative of the curve, which I don't think I can work out.
Zeeshan
Rather than looking for a point of tangency, (x,y), you can look for a point on a graph of discrete points such that the straight line from it to the base point (x0,y0) will have the two adjacent and opposite points of the graph lying on the same side of this line. That would be your approximation to a point of tangency to the graph, and it does not involve finding a derivative. It would involve checking certain linear inequalities that should be satisfied by the point (x,y). Since your graph has only a finite number of points, you should be able to do this with a finite search for such a point.

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 15 Nov 2014

Commented:

on 16 Nov 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!