简体   繁体   English

解决R中的非线性方程

[英]Solving nonlinear equation in R

I have system of equations 我有方程式

x + y - xy = c1
x + z - xz = c2
ay + bz = c3

(a,b, c1,c2 and c3 are known) I want to know if this set of equation have a closed form solution. (已知a,b,c1,c2和c3)我想知道这组方程是否具有封闭形式的解决方案。 Or is optim best way to solve it accurately in R? 还是在R中准确解决问题的最佳最佳方法?

I'd recommend rSymPy , the R port of the awesome python library for symbolic math. 我建议rSymPy ,真棒python库的R端口,用于符号数学。

library(rSymPy)
sympy("var('x,y,a,b,z,c1,c2,c3')") # declare vars
sympy("solve([Eq(x+y-x*y,c1),Eq(x+z-x*z,c2),Eq(a*y-b*z,c3)],[x,y,z])",
      retclass="Sym")

If you're too lazy to do the algebra: 如果您懒得做代数:

Wolfram Alpha says in the most general case (assuming none of these denominators are zero): Wolfram Alpha说在最一般的情况下(假设这些分母都不为零):

x=(a*c1+b*c2-c3)/(a+b-c3)
y=(b*c1-b*c2-c1*c3+c3)/(-a*c1+a-b*c2+b)
z=(a*(c1-c2)+(c2-1)*c3)/(a*(c1-1)+b*(c2-1))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM