'Need help setting up dataframe with parameters and a few functions

I'm trying to set the following up as a dataframe and vary the parameter d to be from 0.05 to 0.5 by 0.05. The value that I'm most interested in is the s1_limiting_ratio. I'm still pretty new to R so setting up dataframes is a little confusing to me still.

r <- 0.7
g1 <- 0.00000000175
g2 <- 0.000000296
v1 <- 0.000000296
v2 <- 0.000000296
k1 <- 2.8
k2 <- 7.7
s01 <- 1
s02 <- 400
d <- 0.05

s1_star <- (r*g1*k1*d)-((v1*(r-d))-r*g1*d)
s2_star <- (r*g2*k2*d)-((v2*(r-d))-r*g2*d)
s1_limiting_equation <- s1_star+((s02-s2_star)*(g1/g2))
s1_limiting_ratio <- s02/s1_limiting_equation

Thank you!



Solution 1:[1]

r <- 0.7
g1 <- 0.00000000175
g2 <- 0.000000296
v1 <- 0.000000296
v2 <- 0.000000296
k1 <- 2.8
k2 <- 7.7
s01 <- 1
s02 <- 400

df <- data.frame(d = seq(0.05, .5, 0.05)) %>%
  mutate(
    s1_star = (r*g1*k1*d)-((v1*(r-d))-r*g1*d),
    s2_star = (r*g2*k2*d)-((v2*(r-d))-r*g2*d),
    s1_limiting_equation  = s1_star+((s02-s2_star)*(g1/g2)),
    s1_limiting_ratio = s02/s1_limiting_equation
  )

Output:

      d       s1_star      s2_star s1_limiting_equation s1_limiting_ratio
1  0.05 -1.921672e-07 -1.02268e-07             2.364865          169.1429
2  0.10 -1.771345e-07  2.66400e-09             2.364865          169.1429
3  0.15 -1.621017e-07  1.07596e-07             2.364865          169.1429
4  0.20 -1.470690e-07  2.12528e-07             2.364865          169.1429
5  0.25 -1.320362e-07  3.17460e-07             2.364865          169.1429
6  0.30 -1.170035e-07  4.22392e-07             2.364865          169.1429
7  0.35 -1.019707e-07  5.27324e-07             2.364865          169.1429
8  0.40 -8.693800e-08  6.32256e-07             2.364865          169.1429
9  0.45 -7.190525e-08  7.37188e-07             2.364865          169.1429
10 0.50 -5.687250e-08  8.42120e-07             2.364865          169.1429

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 langtang