Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我正在用RStudio写一个程序来计算平衡势,它只输出Inf_R - Fatal编程技术网

我正在用RStudio写一个程序来计算平衡势,它只输出Inf

我正在用RStudio写一个程序来计算平衡势,它只输出Inf,r,R,我正在写一个程序,自动计算细胞中给定离子的能斯特势。所以,我让用户指定哪个离子,它的电荷,以及它们在细胞内外的浓度。我定义了常数,用R格式写了方程,我一直得到的输出是Inf 由于我是R的新手,我很确定我在代码中的某个地方犯了错误。所以,我需要你的帮助来修改我的代码,并告诉我我做错了什么 readline("Which ion will you use to measure the potential equilibrium? = ") z<-as.integer(readline("Wha

我正在写一个程序,自动计算细胞中给定离子的能斯特势。所以,我让用户指定哪个离子,它的电荷,以及它们在细胞内外的浓度。我定义了常数,用R格式写了方程,我一直得到的输出是Inf

由于我是R的新手,我很确定我在代码中的某个地方犯了错误。所以,我需要你的帮助来修改我的代码,并告诉我我做错了什么

readline("Which ion will you use to measure the potential equilibrium? = ")
z<-as.integer(readline("What is the ion charge? = "))
co<-as.integer(readline("¿What is the extracelular concentration of the ion (mM) = "))
ci<-as.integer(readline("¿What is the intracelular concentration of the ion (mM) = "))

#Defining constants

R<-8.3145 # unit J/K.mol
Tbody<-310.15 # K=Cº+273.15; Cº=37º body temperature
Faraday<-96485.337 # unit C/mol Faraday constant

#Equation
Veq<-((R*Tbody)/(z*Faraday))*log((co/ci), base = exp(1))  
Veq_mV<-Veq*1000 # from V to mV

#output
cat("The equilibrium potential for ",ion," is: ",Veq_mV)
readline(“您将使用哪个离子来测量电位平衡?=”)

z代码中的问题是由将输入转换为整数引起的。使用
as.numeric
而不是
as.integer
将保留任何小数点后的值
as.integer
将截断小数,因此0.0001的Ca2+浓度将被
as.integer
解释为0,并将导致被0除的错误,导致输出
Inf

试试这个:

readline("Which ion will you use to measure the potential equilibrium? = ")
z<-as.numeric(readline("What is the ion charge? = "))
co<-as.numeric(readline("¿What is the extracelular concentration of the ion (mM) = "))
ci<-as.numeric(readline("¿What is the intracelular concentration of the ion (mM) = "))

#Defining constants

R<-8.3145 # unit J/K.mol
Tbody<-310.15 # K=Cº+273.15; Cº=37º body temperature
Faraday<-96485.337 # unit C/mol Faraday constant

#Equation
Veq<-((R*Tbody)/(z*Faraday))*log((co/ci), base = exp(1))  
Veq_mV<-Veq*1000 # from V to mV

#output
cat("The equilibrium potential for ",ion," is: ",Veq_mV)
readline(“您将使用哪个离子来测量电位平衡?=”)

z代码中的问题是由将输入转换为整数引起的。使用
as.numeric
而不是
as.integer
将保留任何小数点后的值
as.integer
将截断小数,因此0.0001的Ca2+浓度将被
as.integer
解释为0,并将导致被0除的错误,导致输出
Inf

试试这个:

readline("Which ion will you use to measure the potential equilibrium? = ")
z<-as.numeric(readline("What is the ion charge? = "))
co<-as.numeric(readline("¿What is the extracelular concentration of the ion (mM) = "))
ci<-as.numeric(readline("¿What is the intracelular concentration of the ion (mM) = "))

#Defining constants

R<-8.3145 # unit J/K.mol
Tbody<-310.15 # K=Cº+273.15; Cº=37º body temperature
Faraday<-96485.337 # unit C/mol Faraday constant

#Equation
Veq<-((R*Tbody)/(z*Faraday))*log((co/ci), base = exp(1))  
Veq_mV<-Veq*1000 # from V to mV

#output
cat("The equilibrium potential for ",ion," is: ",Veq_mV)
readline(“您将使用哪个离子来测量电位平衡?=”)
Z