Hey guys, I am very new to coding (as in this is my first code). I don't fully understand that minutia that goes into coding, but I am trying to make my life a little easier when it comes to my Chemistry class. We are constantly having to solve for pH and concentrations of compounds. All of the compounds can be solved in terms of hydrogen concentration, H. I am trying to figure out why I get the error "target of assignment expands to non-language object" in my code. I think my problem has something to do for how I am defining H initially. I could also be using the completely wrong language for this sort of problem. Any feedback would be greatly appreciated. The professor told us today that the H value should equal 10^(-7.21)/
Ka1 <- 10^(-6.52)
Ka2 <- 10^(-10.56)
Kw <- 10^(-14.704)
Kso <- 10^(-8.09)
Kh <- 10^(-1.2)
Pco2 <- 10^(-3.5)
H.low <- 0
H.high <- Kw
H.int <- 0.001
for (H in seq(H.low,H.high,H.int)) {
OH <- Kw/H
denom <- (H^2)+(H*Ka1)+(Ka1*Ka2)
Alpha0 <- (H^2)/ denom
Alpha1 <- (H*Ka1) / denom
Alpha2 <- (Ka1*Ka2) / denom
H2CO3 <- Kh*50*Pco2
Ct <- H2CO3 / Alpha0
HCO3 <- Alpha1 * Ct
CO3 <- Alpha2 * Ct
Ca <- Kso / (Alpha2 * Ct)
OH + HCO3 + 2*CO3 - 2*Ca - H
}
solve.default (H,OH, H2CO3, HCO3,CO3,Ca,Ct)