Using R to solve equations

2019-06-21 20:24发布

问题:

How might I solve for the roots of an equation of the following form numerically in R:

f(r)=r*c+1-B*c-exp(-M(B-r))

Where M, B and c are known constants.

Thanks in advance.

回答1:

Since R can not do this functionality you might want to use a superset package like Sage. Sage includes R and many other packages and can do what you want using a webbrowser interface. The site is http://www.sagemath.org/

Examples are located at: http://www.sagemath.org/doc/reference/sage/symbolic/relation.html

You can try stuff like the following at: http://www.sagenb.org/

var('r', 'c', 'B', 'M')
f = r*c+1-B*c-exp(-M(B-r))
print solve(f, r)

The results of this is:

r == (B*c + e^(-B + r) - 1)/c