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

96 views (last 30 days)
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)

Roger Stafford
Roger Stafford on 15 Nov 2014
Edited: Roger Stafford on 15 Nov 2014
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
Zeeshan
Zeeshan on 15 Nov 2014
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
Roger Stafford
Roger Stafford on 16 Nov 2014
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 Financial Data Analytics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!