Hello R-list, How can I row wise solve a function for which the input variables are written in a matrix or a vector and have the calculated output added to the matrix or written in a vector? To specify my case in particular I continue: I would like R to calculate for me a value for ‘t’ which is function of input parameters A and B, which are comprised in a matrix called ‘ddt’ and some other constants. q,p,u,v in this example. The equation (q*(1-exp(u*B*t))+( p*(1-exp(v*B*t)-A) A and B may sometimes be ‘missing values’ (NA (not a number)) because there isn’t always a result for each time step. The matrix ddt looks like this Datetime B A t [772,] 12/12/2005 15:27:12 NA NA NA [773,] 12/12/2005 16:27:12 5000000 1.24480000 NA [774,] 12/12/2005 17:27:12 NA NA NA [775,] 13/12/2005 13:27:12 7012500 2.64038000 NA [776,] 13/12/2005 14:27:12 NA NA NA [777,] 13/12/2005 15:31:28 NA NA NA I’ve tried to calculate t as followed Af<-function(i,t){ (q*(1-exp(u*ddt[i,2]*t))+( p*(1-exp(v*ddt[i,2]*t)- ddt[i,3]) Because input B is listed in the second column and input A is listed in the third column of the matrix ddt. The fourth column in ddt is meant for the row wise output values of ‘t’. To calculate ‘t’ I've tried output<-function(i){uniroot(Af,c(0,9999),i=i)} Uniroot has been used on single input values for A and B and gives good results and I would like to automate this. Therefore I tried to use mapply t<-mapply(output,i=i) This seems not work and therefore I’m asking the list: “how can I calculate in R the row wise value for ‘t’?” Do you have a quick solution for it? Kind regards, Gunter Eerdekens -- --------------------------------------------------------------------- Gunter.Eerdekens@ua.ac.be ---------------------------------------------------------------------- [[alternative HTML version deleted]]
Hello R-list, How can I row wise solve a function for which the input variables are written in a matrix or a vector and have the calculated output added to the matrix or written in a vector? To specify my case in particular I continue: I would like R to calculate for me a value for ‘t’ which is function of input parameters A and B, which are comprised in a matrix called ‘ddt’ and some other constants. q,p,u,v in this example. The equation (q*(1-exp(u*B*t))+( p*(1-exp(v*B*t)-A) A and B may sometimes be ‘missing values’ (NA (not a number)) because there isn’t always a result for each time step. The matrix ddt looks like this Datetime B A t [772,] 12/12/2005 15:27:12 NA NA NA [773,] 12/12/2005 16:27:12 5000000 1.24480000 NA [774,] 12/12/2005 17:27:12 NA NA NA [775,] 13/12/2005 13:27:12 7012500 2.64038000 NA [776,] 13/12/2005 14:27:12 NA NA NA [777,] 13/12/2005 15:31:28 NA NA NA I’ve tried to calculate t as followed Af<-function(i,t){ (q*(1-exp(u*ddt[i,2]*t))+( p*(1-exp(v*ddt[i,2]*t)- ddt[i,3]) Because input B is listed in the second column and input A is listed in the third column of the matrix ddt. The fourth column in ddt is meant for the row wise output values of ‘t’. To calculate ‘t’ I've tried output<-function(i){uniroot(Af,c(0,9999),i=i)} Uniroot has been used on single input values for A and B and gives good results and I would like to automate this. Therefore I tried to use mapply t<-mapply(output,i=i) This seems not work and therefore I’m asking the list: “how can I calculate in R the row wise value for ‘t’?” Do you have a quick solution for it? Kind regards, Gunter Eerdekens -- --------------------------------------------------------------------- Gunter.Eerdekens@ua.ac.be ---------------------------------------------------------------------- [[alternative HTML version deleted]]
Apparently Analagous Threads
- Solving a simple linear equation using uniroot give error object 'x' not found
- Solving a simple linear equation using uniroot give error object 'x' not found
- Solving the equation using uniroot
- Problem : solving a equation with R , fail with uniroot function
- ZFS Dedupe reporting incorrect savings