> Torsten <
Torsten.Hen...@umsicht.fraunhofer.de> wrote in message <
ed4d4b74-bc6e-4da3-9dea-e47f3b205...@dq9g2000vbb.googlegroups.com>...
> > On 10 Feb., 16:38, "James " <
jameskja...@gmail.com> wrote:
> > > I have an array of X co-ordinates and another array of Y co-ordinates which when plotted gives a curve.
> > > could somebody tell me how to find the tangent or slope at each of these coordinates?
>
> > > Thank you!!
>
> > > James
>
> > An approximation for the slope at point X_(i) is (Y_(i+1)-Y_(i-1))/
> > (X_(i+1)-X_(i-1)) (central difference).
> > At the end points X_(1) and X_(n), you could use one-sided
> > differences:
> > at X_(1): (Y_(2)-Y_(1))/(X_(2)-X_(1)) and at X_(n): (Y_(n)-Y_(n-1))/
> > (X_(n)-X_(n-1))
>
> > Best wishes
> > Torsten.- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
I just noticed that the approximation is only valid if the X-
coordinates
all have equal distance, i.e. X_(i+1)-X_(i) = deltax = constant.
If the X-coordinates have different distance, then you should use
at x=X(1) :
slope approximately
Y(1)*((X_(1)-X_(2))+(X_(1)-X_(3))/((X_(1)-X_(2))*(X_(1)-X_(3))) +
Y(2)*(X_(1)-X_(3))/((X_(2)-X_(1))*(X_(2)-X_(3))) +
Y(3)*(X_1)-X_(2))/((X_(3)-X_(2))*(X_(3)-X_(1)))
in inner points X=X_(i)
slope approximately
Y_(i-1)*(X_(i)-X_(i+1))/((X_(i-1)-X_(i))*(X_(i-1)-X_(i+1))) +
Y_(i)*((X_(i)-X_(i-1))+(X_(i)-X_(i+1)))/((X_(i)-X_(i-1))*(X_(i)-X_(i
+1))) +
Y_(i+1)*(X_(i)-X_(i-1))/((X_(i+1)-X_(i))*(X_(i+1)-X_(i-1)))
at X=X_(n):
Y_(n-2)*(X_(n)-X_(n-1))/((X_(n-2)-X_(n-1))*(X_(n-2)-X_(n))) +
Y_(n-1)*(X_(n)-X_(n-2))/((X_(n-1)-X_(n-2))*(X_(n-1)-X_(n))) +
Y_(n)*((X_(n)-X_(n-1))+(X_(n)-X_(n-2)))/((X_(n)-X_(n-1))*(X_(n)-
X_(n-2)))
Best wishes
Torsten.