elizarov
05/04/2019, 1:19 PMval x = D(2) // define variable(s) and their values
val y = grad { sqr(x) + 5 * x + 3 } // write formulae in grad context
assertEquals(17.0, y.x) // the value of result (y)
assertEquals(9.0, x.d) // dy/dx
altavir
05/04/2019, 1:40 PMelizarov
05/04/2019, 2:31 PMaltavir
05/04/2019, 2:47 PMaltavir
05/04/2019, 2:47 PMelizarov
05/04/2019, 2:48 PMelizarov
05/04/2019, 2:50 PMaltavir
05/04/2019, 2:51 PMelizarov
05/04/2019, 2:51 PMelizarov
05/04/2019, 2:52 PMaltavir
05/04/2019, 2:54 PMaltavir
05/04/2019, 2:56 PMelizarov
05/04/2019, 2:57 PMsin()
function uses and how concrete and concise mine is:
fun AD.sin(x: D): D = derive(D(sin(x.x))) { z ->
x.d += z.d * cos(x.x)
}
altavir
05/04/2019, 2:59 PMelizarov
05/04/2019, 2:59 PMaltavir
05/04/2019, 2:59 PMaltavir
05/04/2019, 3:01 PMelizarov
05/04/2019, 3:01 PMelizarov
05/04/2019, 3:02 PMaltavir
05/04/2019, 3:03 PMaltavir
05/04/2019, 5:54 PMgrad
is a bit confusing since gradient is usually used for scalar multivariate function and generates vector, not scalar.
It is still nice to have, I will generalize it for different types of object using ExtendedField
so it will be applicable to complex numbers and (in future) to vectors of numbers.elizarov
05/04/2019, 8:10 PMaltavir
05/05/2019, 7:20 AMaltavir
05/05/2019, 7:21 AM