A simple example of using r language to achieve a derivative

Source: Internet
Author: User

When learning the derivative, the teacher explains this, assuming y=f (x), the derivative process of the point (X0,Y0) is as follows:
Set DX is a very small number
= Y0+dy=f (X0+DX)
= Dy=f (X0+DX)-y0
Then at this point the derivative a=dy/dx
This assumes that the DX is very small, so x0 to (X0+DX) is short, can be approximated to a straight line, then DY/DX can be regarded as the slope of the point (X0,y0) and the point (X0+dx,y0+dy) connected to a straight line
So the meaning of the derivative of a point can also be interpreted as the rate of change at that point

Here is a simple example using the R language:
Hypothesis: y=1/x, the derivative of the point (

X<-seq (0,3,by=0.0001)

y<-1/x # #生成模拟数据

D_point<-data.frame (x, y)

X0<-1
Y0<-1/x0 # #点 (a)


DX=0.0001 # #dx很小
dy<-1/(X0+DX)-y0


A<-DY/DX # #导数
B<-y0-a*x0 # #直线与y抽的截距

Library (GGPLOT2) # #画图
P<-ggplot (Subset (D_POINT,Y<=3), AES (x, y))
P+geom_line () +geom_abline (intercept=b, slope=a,linetype=2) +geom_point (Data=data.frame (X=1,y=1), AES (colour= "Red" ))

# #结果:

A simple example of using r language to achieve a derivative

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.