This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Line { | |
constructor(m, c) { | |
this.m = m; | |
this.c = c | |
} | |
apply(x) { | |
return this.m * x + this.c; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Integration { | |
def integrate(fn: Double => Double, | |
interval: (Double, Double), | |
precision: Double = 0.0001): Double = { | |
def areaBetween(start: Double, end: Double): Double = (fn(end) + fn(start)) / 2 * (end - start) | |
def doIntegrate(start: Double, end: Double, area: Double): Double = { | |
val mid = (start + end)/2 | |
val left = areaBetween(start, mid) | |
val right = areaBetween(mid, end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object AutoDiff { | |
// When we are computing derivative for say f(x) we would like to keep track of dx/dt (t being independent variable) | |
// in-case t == x then diff = 1. | |
// Suppose x is not a scalar ie., R^k then we would like to keep track of partial derivatives on each co-ordinate. | |
// Hence V is a vector space (which is just enough for our case), this would be final Jacobian | |
case class Dual[K, V](value: K, diff: V) | |
// We define a Vectorspace V over the field K, we can reduce the generalization by keeping K == Double and it should mostly work too. |
OlderNewer