Math 优化函数(如电容器充电)曲线的参数以拟合数据
在我尝试将形式为Math 优化函数(如电容器充电)曲线的参数以拟合数据,math,kotlin,mathematical-optimization,gradient-descent,nonlinear-optimization,Math,Kotlin,Mathematical Optimization,Gradient Descent,Nonlinear Optimization,在我尝试将形式为y=a*(1-exp(-x/b))的函数拟合到某些给定数据时,我有点不知所措。我怀疑它可能会有所帮助,但我还没有成功地使用它。下面你可以找到一些代码来解释我想要实现的目标 import kotlin.math.exp import kotlin.random.Random // Could be interpreted as a capacitor-charging curve with Vs = a and t = b fun fGeneric(a: Double, b: D
y=a*(1-exp(-x/b))
的函数拟合到某些给定数据时,我有点不知所措。我怀疑它可能会有所帮助,但我还没有成功地使用它。下面你可以找到一些代码来解释我想要实现的目标
import kotlin.math.exp
import kotlin.random.Random
// Could be interpreted as a capacitor-charging curve with Vs = a and t = b
fun fGeneric(a: Double, b: Double, x: Double) = a * (1 - exp(-x / b))
fun fGiven(x: Double) = fGeneric(a = 10.0, b = 200.0, x = x)
fun fGivenWithNoise(x: Double) = fGiven(x) + Random.nextDouble(-0.1, 0.1)
fun main() {
val xs = (0..1000).map(Int::toDouble).toDoubleArray()
val ys = xs.map { x -> fGivenWithNoise(x) }.toDoubleArray()
// todo: From data, find a and b, such that fGeneric fits optimally.
}
我是否需要提供多变量微分向量函数
接口的实现?如果是这样,它应该是什么样子?通过使用以下方法找到了解决方案:
结果看起来不错:
9.998170586347115
200.14238710377768
9.998170586347115
200.14238710377768