I have found the yield of a crop (Y) as a function of its nitrogen offtake (U) i.e., Y(U).
The rest of the values for this particular crop are:
Y_crit | U_crit | Q | p | U_max | Y |
---|---|---|---|---|---|
12327.9 | 123.2790 | 57.14286 | 0.75 | 198.38 | 14170 |
I want to solve for U.
I tried solving this using a binary search algorithm, using the uniroot() and polyroot(), all to no avail :(
I tried defining it as
fn <- function(U)
{
Y - Y_crit - Q * (U-U_Crit) + ((Q/(p+1)) * ((U - U_crit)/(U_max - U_crit))^(p+1) * (U_max - U_crit)
}
U <- polyroot(fn)
print(U)
but it says: "Error in polyroot(fn) : unimplemented type 'closure' in 'polyroot'"
I had first presented the value of Y as 14170 (=Y_max) but then confusing it with data for another crop, changed it to 11000. I have now changed it back.
I have rewritten the function in order to make it more clear what it is computing, there is an error in the question's version (wrong parenthesis).
U = 123.79
, the value in the data.frame, until a visual inspection found an interval where the root is.Created on 2022-12-22 with reprex v2.0.2
Edit
According to its documentation, package
optimx
But it only minimises the objective function, so write a wrapper around it,
gn
below.Created on 2022-12-23 with reprex v2.0.2
The first run with 4 methods gives similar results for methods BFGS and CG. The second run keeps only these two methods.
The function's values are the symmetric of the values in column
value
.Data
Here is the posted arguments data set as copy&paste able code.
Created on 2022-12-22 with reprex v2.0.2