http://www.mathworks.com/matlabcentral/newsreader/view_thread/245058
MATLAB Central Newsreader  tangent line from curve graph
Feed for thread: tangent line from curve graph
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sun, 22 Feb 2009 00:19:01 +0000
tangent line from curve graph
http://www.mathworks.com/matlabcentral/newsreader/view_thread/245058#629960
Stephen
hi friends,<br>
i need your help. I wish to do tangent line from curve graph plotted.<br>
I have data for P at time,t. Then, i plot the graph of P against t which shows it is curve line. By using only this graph, how can i do tangent line at specific t in order to obtain value for dP/dt?? In addition, no equation for P is available.<br>
<br>
Thanks in advance.

Sun, 22 Feb 2009 00:34:02 +0000
Re: tangent line from curve graph
http://www.mathworks.com/matlabcentral/newsreader/view_thread/245058#629963
Matt Fig
At point n, you could find the forward difference or the backward difference or take a secant from n1 to n+1. For example:<br>
<br>
dy/dx ~ [P(n+1)  P(n)] / [(n+1)  n]<br>
<br>
Alternatively, you could fit a polynomial or spline and take it's derivative at that point. There are many ways to approximate the derivative.

Sun, 22 Feb 2009 02:22:02 +0000
Re: tangent line from curve graph
http://www.mathworks.com/matlabcentral/newsreader/view_thread/245058#629966
Stephen
Thanks for response, Matt Fig.<br>
I really not good in matlab, so can u explain a little bit about forward difference, backward difference and secant. I'm not really understand.<br>
I already tried spline, but seems it shows the values of P, not dP/dt.<br>
Maybe i wrong in giving information earlier but what i wish to obtain is the value of dP/dt at specified t and in my mind, this value can be obtained by finding tangent line (or slope) at that specified t.<br>
Meaning that, the tangent (or slope) should represents as dP/dt.<br>
<br>
Sorry,if i already misunderstood your opinion.

Sun, 22 Feb 2009 03:16:01 +0000
Re: tangent line from curve graph
http://www.mathworks.com/matlabcentral/newsreader/view_thread/245058#629969
Matt Fig
"Stephen " <mulan_nuri@yahoo.com> wrote in message <gnqcsa$cnb$1@fred.mathworks.com>...<br>
> Thanks for response, Matt Fig.<br>
> I really not good in matlab, so can u explain a little bit about forward difference, backward difference and secant. I'm not really understand.<br>
<br>
<br>
Those aren't terms specific to Matlab. I was talking about numerical derivative approximations. See this link:<br>
<a href="http://en.wikipedia.org/wiki/Numerical_differentiation">http://en.wikipedia.org/wiki/Numerical_differentiation</a><br>
For example, say we have two vectors:<br>
x = 0:.1:pi;<br>
y = sin(x); % Pretend we don't know it is sin(x) for arguments sake.<br>
idx = find(x==1) % We will find the derivative at x = 1;<br>
Because the slope is decreasing at x=1, the forward difference will underestimate the derivative:<br>
(y(idx+1)y(idx))/(x(idx+1)x(idx))<br>
while the backward difference will overestimate the derivative:<br>
(y(idx)y(idx1))/(x(idx)x(idx1))<br>
The secant difference is the average of these:<br>
(y(idx+1)y(idx1))/(x(idx+1)x(idx1))<br>
Compare these estimates with the true derivative:<br>
cos(1)<br>
<br>
> I already tried spline, but seems it shows the values of P, not dP/dt.<br>
> Maybe i wrong in giving information earlier but what i wish to obtain is the value of dP/dt at specified t and in my mind, this value can be obtained by finding tangent line (or slope) at that specified t.<br>
> Meaning that, the tangent (or slope) should represents as dP/dt.<br>
> <br>
> Sorry,if i already misunderstood your opinion.<br>
<br>
<br>
The idea with the polynomial fit is that it is easy to take the derivative of a polynomial. You fit a polynomial to the data, over some region of interest, then take the derivative of the polynomial. If the fit is very good, the derivative should be o.k. Things can go wrong with this method too, that is why numerical differentiation is tricky.

Sun, 22 Feb 2009 04:50:18 +0000
Re: tangent line from curve graph
http://www.mathworks.com/matlabcentral/newsreader/view_thread/245058#629978
Roger Stafford
"Stephen " <mulan_nuri@yahoo.com> wrote in message <gnq5ll$bih$1@fred.mathworks.com>...<br>
> hi friends,<br>
> i need your help. I wish to do tangent line from curve graph plotted.<br>
> I have data for P at time,t. Then, i plot the graph of P against t which shows it is curve line. By using only this graph, how can i do tangent line at specific t in order to obtain value for dP/dt?? In addition, no equation for P is available.<br>
> <br>
> Thanks in advance.<br>
<br>
If you are willing to do additional computation, you can approximate the derivative (slope) at each point with the following second order differencing. Suppose t and p are nelement row vectors. (The stuff below can easily be adjusted for column vectors.) Then do this:<br>
<br>
td = [t(3),t(1:n1)]; tu = [t(2:n),t(n2)];<br>
pd = [p(3),p(1:n1)]; pu = [p(2:n),p(n2)];<br>
dpdt = ((pup)./(tut).*(ttd)+(ppd)./(ttd).*(tut))./(tutd);<br>
<br>
Then dpdt will be an nelement row vector of corresponding derivative approximations of dp/dt. The fact that it is a second order approximation means that if you make p any linear or quadratic function of t, the quantity dpdt is an exact derivative at each of the points. Note that the tintervals need not be equallyspaced for this to be true. Note also that this property holds even for the two endpoints.<br>
<br>
There are also some higher order derivative approximations on the file exchange, probably listed under the term "gradient".<br>
<br>
Roger Stafford

Sun, 22 Feb 2009 09:46:02 +0000
Re: tangent line from curve graph
http://www.mathworks.com/matlabcentral/newsreader/view_thread/245058#629994
Stephen
Thanks to Matt Fig and Roger Stafford.<br>
You have give me some valuable ideas on what should i do. just i need to further study about that. I have studied before but already forgotten. ;P<br>
<br>
Thanks again!!