I have two simple equations.
46.85 = r/k
8646.709 = r/(k^2)
I am trying to solve for r and k and I tried setting up my equations as follows
model <- function(r,k) { c(46.85 = r/k,
8646.709 = r/(k^2))}
ss <- multiroot(f = model, start = c(1, 1))
I am seeing some errors. Not sure where I am going wrong. Any advice on how to solve this equation for r
and k
is much appreciated.
You appear to be using package
rootSolve
. The way you have specified your function is very wrong. You should have something like thisand then try this:
multiroot
cannot find a solution. Output iswhich is not a solution. Trying other starting values doesn't help.
I will demonstrate two ways of solving your system of equations: manually and using another package. You can solve your equations manually like this: From the first equation we have
Substitute this in the second equation and simplfy and we get
Insert the value found for
k
in the equation forr
and display the values forr
andk
and then run the model function like this
giving output
The second method involves using another package namely
nleqslv
. It has more methods and strategies for finding solutions of system of nonlinear equations. It also has a testfunction for investigating which method and/or strategy works. Like thisOutput is
Read the help page for function
nleqslv
from start to finish to see what the methods and global columns mean. From the output it seems that the Broyden method is not very successful. You can also see that a standard Newton method (withnone
in theglobal
column) cannot find a solution. So let's try thecline
global strategy in a call tonleqslv
.with output
Comparing the solution found with the manually calculated solution shows that
nleqslv
found the solution.