我试图使用抛物线插值找到给定函数的最小值。
目的:
使用函数’g(x)‘找到另一个函数’f(x)’的最小值用于估算的函数 - > g(x)= a0 + ……
看起来在更广泛的数学意义上,3点不足以唯一地定义抛物线。 5个点应该足以唯一地定义任何圆锥曲线。看到:
https://www.quora.com/How-many-points-are-needed-to-uniquely-define-a-parabola-and-the-other-conics-Is-there-only-one-parabola-passing-透顶点对的一给出的三角
除非您有足够的点来唯一地定义抛物线,否则您的优化将有多个答案。
所以错误是最小化平方误差,因为这将提供一个独特的解决方案
纠正后的解决方案如下:
# Actual function to estimate the minimum value of actual <- function(x){ result <- -x *(1-x) return(result) } # The estimation function whose parameters a0,a1,a2 are unknown parabola <- function(par,x){ a0 <- par[1] a1 <- par[2] a2 <- par[3] result <- a0+a1*x+a2*x^2 return(result) } # finding the difference between the functions for three given values (x0,x1,x2) difference_function <- function(par,x){ x0 <- par[4] x1 <- par[5] x2 <- par[6] result <- sum((actual(x0)-parabola(par,x0))^2,(actual(x1)-parabola(par,x1))^2, (actual(x2)-parabola(par,x2))^2) return(result) } find_parameters <- function(){ temp <- optim(par=c(0,-1,1,0.1,0.8,0.9), fn=difference_function) a0 <- temp$par[1] a1 <- temp$par[2] a2 <- temp$par[3] return(list=c(a0=a0,a1=a1,a2=a2)) } find_parameters()