如何在 R 中求解非线性方程
How to solve nonlinear equations in R
比如我尝试求解x: 12*exp(-2x/4)=0.5,或者x^2+3x^4+9x^5=10,请问R中有没有什么方法可以求解这样的方程式?
尝试使用 uniroot
函数
r1 <- uniroot(function(x) 12*exp(-x/2) - 0.5, c(-1000, 1000))
r2 <- uniroot(function(x) x^2 + 3*x^4 + 9*x^5 - 10, c(-1000, 1000))
r1$root
[1] 6.356108
r2$root
[1] 0.943561
您必须定义:
f(x) = 0
类型的函数(并删除相等的第二个成员)
搜索解决方案的区间
比如我尝试求解x: 12*exp(-2x/4)=0.5,或者x^2+3x^4+9x^5=10,请问R中有没有什么方法可以求解这样的方程式?
尝试使用 uniroot
函数
r1 <- uniroot(function(x) 12*exp(-x/2) - 0.5, c(-1000, 1000))
r2 <- uniroot(function(x) x^2 + 3*x^4 + 9*x^5 - 10, c(-1000, 1000))
r1$root
[1] 6.356108
r2$root
[1] 0.943561
您必须定义:
f(x) = 0
类型的函数(并删除相等的第二个成员)搜索解决方案的区间