I am using D to get derivatives of a function. However, R does not simplify the expression when returning the derivative. I need to figure out if a function has a derivative that can be expressed generically. Is there some way in R to simplify the expression?
> D(expression(sqrt(1 - x^2)), 'x')
-(0.5 * (2 * x * (1 - x^2)^-0.5))
> D(D(expression(sqrt(1 - x^2)), 'x'), 'x')
-(0.5 * (2 * (1 - x^2)^-0.5 - 2 * x * (-0.5 * (2 * x * (1 - x^2)^-1.5))))
Secondly, is there a way in R to do numerical integration?
We use a variety of different notations to express the derivative of a function. In Example 3.2. 2 we showed that if f(x)=x2−2x, then f′(x)=2x−2. If we had expressed this function in the form y=x2−2x, we could have expressed the derivative as y′=2x−2 or dydx=2x−2.
In very simple words, the derivative of a function f(x) represents its rate of change and is denoted by either f'(x) or df/dx. Let's first look at its definition and a pictorial illustration of the derivative. Illustration of the Definition of a Function Derivative.
A derivative helps us to know the changing relationship between two variables. Mathematically, the derivative formula is helpful to find the slope of a line, to find the slope of a curve, and to find the change in one measurement with respect to another measurement. The derivative formula is ddx. xn=n.
library(Ryacas)
x <- Sym("x")
Simplify(deriv(sqrt(1 - x^2),x,2)) # return the result simplified
gives
expression((x^2 - 1 - x^2)/root(1 - x^2, 2)^3)
You can also try
PrettyForm(Simplify(deriv(sqrt(1 - x^2),x,2)))
which gives
2 2
x - 1 - x
---------------
3
/ 2 \
Sqrt\ 1 - x /
As for numerical integration try giving this to see what is available
library(sos)
findFn('{numerical+integration}')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With