| 374 | } |
| 375 | |
| 376 | double mixedSecondOrderDerivativeAt(const Matrix &layerData, const Index &index, double resolution) |
| 377 | { |
| 378 | /* |
| 379 | * no need for dimensions since the we have to differentiate w.r.t. x and y |
| 380 | * the order doesn't matter. Derivative values are the same. |
| 381 | * Taken from https://www.mathematik.uni-dortmund.de/~kuzmin/cfdintro/lecture4.pdf |
| 382 | */ |
| 383 | |
| 384 | const int numCol = layerData.cols(); |
| 385 | const int numRow = layerData.rows(); |
| 386 | |
| 387 | const double f11 = layerData(bindIndexToRange(index.x() - 1, numRow), |
| 388 | bindIndexToRange(index.y() - 1, numCol)); |
| 389 | const double f1m1 = layerData(bindIndexToRange(index.x() - 1, numRow), |
| 390 | bindIndexToRange(index.y() + 1, numCol)); |
| 391 | const double fm11 = layerData(bindIndexToRange(index.x() + 1, numRow), |
| 392 | bindIndexToRange(index.y() - 1, numCol)); |
| 393 | const double fm1m1 = layerData(bindIndexToRange(index.x() + 1, numRow), |
| 394 | bindIndexToRange(index.y() + 1, numCol)); |
| 395 | |
| 396 | const double perturbation = resolution; |
| 397 | // central difference approximation |
| 398 | // we need to multiply with resolution^2 since we are |
| 399 | // operating in scaled coordinates. Second derivative scales |
| 400 | // with the square of the resolution |
| 401 | return (f11 - f1m1 - fm11 + fm1m1) / (4.0 * perturbation * perturbation) * resolution * resolution; |
| 402 | |
| 403 | } |
| 404 | |
| 405 | bool getMixedSecondOrderDerivatives(const Matrix &layerData, const IndicesMatrix &indices, |
| 406 | double resolution, DataMatrix *derivatives) |
no test coverage detected