marabi
marabi

Reputation: 3

Using mosaicCalc::D() to differentiate expression giving unexpected result

I am attempting to differentiate the expression -1+3*x^2/1+x^2 with respect to x, but the output is incorrect. The correct output should be:

8x/(1+x^2)^2

#> library(mosaicCalc)
#>
#> l=D(-1+3*x^2/1+x^2 ~x)
#> l
function (x) 
8 * x

Edit: I have used parenthesis, but the output is still incorrect

#> t=D((-1+3*x^2)/1+x^2 ~x)
#> t
function (x) 
8 * x

Furthermore, I have used parenthesis for both the numerator and the denominator, and the output for the second derivative is incorrect.

> b = D((-1+3*x^2)/(1+x^2) ~x)
> b
function (x) 
{
    .e1 <- x^2
    .e2 <- 1 + .e1
    x * (6 - 2 * ((3 * .e1 - 1)/.e2))/.e2
}
> k = D(b~ x)
> k
function (x, t) 
0

The correct answer for the second derivative is 8(-3x^2+1)/(1+x^2)^3

https://www.symbolab.com/solver/step-by-step/%5Cfrac%7Bd%7D%7Bdx%7D%5Cfrac%7B8x%7D%7B%5Cleft(1%2Bx%5E%7B2%7D%5Cright)%5E%7B2%7D%7D?or=input

Upvotes: 0

Views: 65

Answers (1)

rpruim
rpruim

Reputation: 320

I think you need b(x) ~ x to get your second derivative. That will give you an expression in x that can be differentiated. As is, you are differentiating an expression that doesn’t depend on x, so the derivative is 0.

I might create an issue on GitHub to see if it is possible to emit a useful message in this case.

Upvotes: 0

Related Questions