Tangent line to a known point on a curve

7 次查看(过去 30 天)
Hi. I have a curve generated by some coordinates and I need to draw a tangent line to some points. Also, above the curve, there's a line parallel to the OX axis (like an asymptote) and I have to mark the point of intersection between it and the tangents I drew before. How can I do that ?
The result should look like this:
And my variables are:
time=[0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75]
res=[6.93 7.1 7.48 7.82 8.12 8.38 8.6 8.81 8.94 9.12 9.24 9.34 9.45 9.54 9.61 9.68]
thank you.

采纳的回答

Shane
Shane 2015-10-16
编辑:Shane 2015-10-16
Well there are a few ways to do it. The simple method of calculating the derivative is by using the data before/after the point of interest to calculate δy/δx. This is a crude method but it depends on what your teacher is looking for. Consider >>diff(res)/5 to calculate the approximate derivative at each point.
The other method is to use the polyfit function to estimate the coefficients of a polynomial function to your data points. This could be done for a 5th order polynomial (for example) as follows:
>> p=polyfit(time,res,5)
>> p1=[5*p(1) 4*p(2) 3*p(3) 2*p(4) p(5)]
>> derivative=polyval(p1,x) %where x is the point of interest.
if you want to see what polyfit is doing, do the following:
p=polyfit(time,res,5);
x1=linspace(0,75);
y1=polyval(p,x1);
plot(time,res)
hold on
plot(x1,y1)
Once you have the derivative and the point, it is easy to calculate the line and plot using the plot function. Same with the asymptote. Look into ezplot as well if you just want to define a text function rather than calculating and defining points.
Once you have the two lines, calculate the intersection point and use the plot function (type ">>help plot" to see a list of options for plotting points...an example could be >>plot(x1,y1,'rs') to plot a red square at the location.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by