I have a simple flow model in R. It comes down to two differential equations that model two state variables in the model, we will call them A and B They are calculated as simple difference equations of the four-component flux1-flux4 , 5 parameters p1-p5 and 6th parameter of_interest , which can take values โโbetween 0-1.
parameters<- c(p1=0.028, p2=0.3, p3=0.5, p4=0.0002, p5=0.001, of_interest=0.1) state <- c(A=28, B=1.4) model<-function(t,state,parameters){ with(as.list(c(state,parameters)),{
I would like to write a function to take the derivative of dAdt with respect to of_interest , set the derivative equation to 0, and then rearrange and solve for the value of_interest . This will be the value of_interest , which maximizes the dAdt function.
So far, I have managed to solve the model in a stable state according to the possible values of_interest , to demonstrate that there should be a maximum.
require(rootSolve) range<- seq(0,1,by=0.01) for(i in range){ of_interest=i parameters<- c(p1=0.028, p2=0.3, p3=0.5, p4=0.0002, p5=0.001, of_interest=of_interest) state <- c(A=28, B=1.4) ST<- stode(y=y,func=model,parms=parameters,pos=T) out<- c(out,ST$y[1])
Then build:
plot(out~range, pch=16,col='purple') lines(smooth.spline(out~range,spar=0.35), lwd=3,lty=1)

How can I analytically solve the value of_interest that maximizes dAdt in R? If an analytical solution is impossible, how can I know, and how can I solve it numerically?
Update: I think this problem can be solved with the deSolve package in R linked here , however I am having problems implementing it using my example.