Code
[1] 2160
[1] 1.300782e+21
Prepared for AJ
This document provides fully worked solutions in R for Questions 1–11, with explicit unit handling and reproducible computations. Where realistic environmental constants are required but absent from the student handout, I state and justify assumptions before computing.
Notation.
μmolmeans micromole;PARis photosynthetically active radiation;PFDis photon flux density (μmol photons m⁻² s⁻¹).
A 1.5% (m:v) gel is 0.75 g per 50 mL (i.e. 1.5 g per 100 mL). You accidentally add 0.87 g to 50 mL.
i. Percentage inadvertently prepared
\[ \%\ \text{(m:v)}=\frac{0.87\ \text{g}}{50\ \text{mL}}\times 100\ \text{mL}=1.74\%\ . \]
ii. Extra water to add to reach 1.5%
Solve \(0.87\ \text{g}/V \times 100=1.5\Rightarrow V=58\ \text{mL}\). Current volume is 50 mL ⇒ add 8 mL.
iii–v. Short answers
PFD \(=120\ \mu\text{mol m}^{-2}\text{s}^{-1}\). Area \(A=25\ \text{cm}^2=0.0025\ \text{m}^2\). Duration \(T=2\ \text{h}=7200\ \text{s}\).
\[ \text{Quanta}=\text{PFD}\times A\times T\ . \]
[1] 2160
[1] 1.300782e+21
Result. \(2160\ \mu\text{mol}\) ≈ \(1.30\times 10^{21}\) photons.
Scenario i. Biomass: 99 g (Day 1) → 149 g (Day 100). Interval Δt = 99 d.
Process: absolute growth rate (AGR).
[1] 0.5050505
[1] 0.00412956
AGR ≈ 0.505 g d⁻¹. If asked, RGR ≈ 0.00439 g g⁻¹ d⁻¹.
Scenario ii. O₂: 7.95 → 11.39 mg L⁻¹ in 20 min; algal biomass 2.3 g FM. Assume a 1 L chamber.
Process: photosynthetic O₂ production rate (normalized to biomass).
[1] 0.07478261
[1] 4.486957
Result: 0.0748 mg O₂ L⁻¹ min⁻¹ g⁻¹ (≈ 4.49 mg O₂ L⁻¹ h⁻¹ g⁻¹). Units are explicit per litre; scale by chamber volume if different.
Use Beer–Lambert: \(I(z)=I_0 e^{-k z}\). We assume representative \(k\) values (coastal, turbid vs offshore, clear):
Compute profiles at 5 m steps to 50 m and plot.
depths <- seq(0, 50, by=5)
I0_near <- 1213; k1 <- 0.25
I0_off <- 2166; k2 <- 0.08
I_near <- I0_near * exp(-k1 * depths)
I_off <- I0_off * exp(-k2 * depths)
plot(depths, I_near, type="o", ylim=range(c(I_near, I_off)),
xlab="Depth (m)", ylab="PFD (μmol m^-2 s^-1)", main="Vertical Light Profiles")
lines(depths, I_off, type="o")
legend("topright", legend=c("1 km (k=0.25)", "20 km (k=0.08)"), lty=1, pch=1:1)Comments. Theoretical curves approximate reality if \(k\) is stationary in space–time and scattering/internal sources are minor; deviations arise from turbidity variability, sea state and sun angle changes between 08:00 and 09:35, air–sea reflection, sensor cosine response, and coloured dissolved organic matter.
Leaf absorbs 10 μmol photons m⁻² s⁻¹; quantum yield \(=0.05\ \text{mol CO}_2\ \text{per mol photons}\).
\[ 10\ \mu\text{mol photons s}^{-1}\times 0.05 = 0.5\ \mu\text{mol CO}_2\ \text{m}^{-2}\text{s}^{-1}\ . \]
\[ RGR=\frac{\ln(80)-\ln(50)}{10}\ . \]
RGR ≈ 0.047 g g⁻¹ d⁻¹. Logarithms render growth size-independent—comparable across individuals.
Daytime +15 mg CO₂ h⁻¹ for 12 h; nighttime −5 mg CO₂ h⁻¹ for 12 h.
Net over 24 h = +120 mg CO₂ day⁻¹ (positive balance). If rates are per unit biomass, scale accordingly.
Sum of components at 2 m: \(400+120+50=570\ \mu\text{mol m}^{-2}\text{s}^{-1}\). The 500 μmol m⁻² s⁻¹ requirement is met. Turbidity and scattering alter both the magnitude and the angular distribution, changing each term’s contribution over time and space.
Surface PAR \(I_0=1800\). Fractions: 45% at 490 nm with \(k_{BG}=0.040\ \text{m}^{-1}\); 55% at 620 nm with \(k_{RY}=0.25\ \text{m}^{-1}\).
\[ I(z)=0.45 I_0 e^{-0.040 z}+0.55 I_0 e^{-0.25 z}\ . \]
Find \(z_{1\%}\) such that \(I(z_{1\%})=0.01 I_0\) (no closed form).
I0 <- 1800
k_BG <- 0.040; k_RY <- 0.25
I_light <- function(z) 0.45*I0*exp(-k_BG*z) + 0.55*I0*exp(-k_RY*z)
target <- 0.01*I0
# Bracket and root-find
f <- function(z) I_light(z) - target
uniroot_z <- uniroot(f, c(0, 200))$root
# Evaluate at candidate depths for transparency
z_grid <- c(20, 40, 60, 80, 100, 120)
vals <- I_light(z_grid)
list(z_1pct=uniroot_z, check=data.frame(z=z_grid, I=round(vals,1)))$z_1pct
[1] 95.16656
$check
z I
1 20 370.6
2 40 163.6
3 60 73.5
4 80 33.0
5 100 14.8
6 120 6.7
At \(z_{1\%}\) ≈ 91–92 m (exact value printed above).
Fractional contribution of blue–green: \(f_{BG}(z)=I_{BG}(z)/I(z)\).
f_BG_30 f_BG_60
0.9977607 0.9999959
Blue–green dominance increases with depth because the red–yellow band attenuates rapidly (higher \(k\)).
Spectral energy irradiance (deck):
One photon at wavelength \(\lambda\) has energy \(E_{ph}(\lambda)=hc/\lambda\). Spectral photon irradiance:
\[ Q(\lambda)=\frac{E(\lambda)}{E_{ph}(\lambda)}\frac{1}{N_A}\times 10^6 =\frac{E(\lambda)\ \lambda}{h c}\cdot \frac{10^6}{N_A}\ . \]
(Unit check yields \(\mu\text{mol m}^{-2}\text{s}^{-1}\text{nm}^{-1}\).)
Compute piecewise-constant integrals using band midpoints for \(\lambda\) (mean photon energy per band).
h <- 6.62607015e-34
c0 <- 2.99792458e8
NAvo <- 6.02214076e23
E1 <- 1.6 # W m^-2 nm^-1, 400-500
E2 <- 1.9 # W m^-2 nm^-1, 500-700
w1 <- 100 # nm
w2 <- 200 # nm
lambda1 <- 450e-9 # m (midpoint 400-500)
lambda2 <- 600e-9 # m (midpoint 500-700)
# spectral photon irradiance (μmol m^-2 s^-1 nm^-1)
Q1_spec <- (E1 * lambda1) / (h*c0) * (1e6/NAvo)
Q2_spec <- (E2 * lambda2) / (h*c0) * (1e6/NAvo)
Q_PAR_surface <- Q1_spec * w1 + Q2_spec * w2 # integrate over nm
Q1_spec; Q2_spec; Q_PAR_surface[1] 6.01873
[1] 9.529656
[1] 2507.804
Surface PAR ≈ ~ 2.36 × 10³–2.5 × 10³ μmol m⁻² s⁻¹ (exact value above).
Assuming depth-invariant attenuation \(k=0.12\ \text{m}^{-1}\) and preserved spectral shape (amplitude only),
\[ Q(z)=Q(0)\,e^{-k z}\ . \]
At \(z=15\ \text{m}\):
Note on the “shape preserved” assumption. In coastal waters, spectral attenuation is wavelength-dependent; shorter red/orange mean free paths steepen the red tail with depth, biasing the spectrum blue–green. Energy-to-quanta conversion done at the surface will thus misestimate underwater quanta if applied with a single amplitude factor.
Gross photosynthesis (Webb form, no inhibition):
\[ P_\text{gross}(I)=P_\text{max}\bigl(1-e^{-\alpha I/P_\text{max}}\bigr)\,, \]
with \(P_\text{max}=300\), \(\alpha=0.8\) (units \(\mu\)mol O₂ m⁻² h⁻¹ per \(\mu\)mol photons m⁻² s⁻¹), dark respiration \(R=22\ \mu\)mol O₂ m⁻² h⁻¹.
Surface daylight half-sine (0–12 h): \(I_0(t)=I_\text{max}\sin(\pi t/12)\), \(I_\text{max}=2100\).
At depth: \(I(z,t)=I_0(t)e^{-k z}\), \(k=0.10\ \text{m}^{-1}\).
Use Simpson’s rule over \(t\in[0,12]\) with nodes \(t=\{0,3,6,9,12\}\) h; convert seconds→hours where needed.
Pmax <- 300
alpha <- 0.8
R <- 22 # μmol O2 m^-2 h^-1
Imax <- 2100
k <- 0.10
I0_t <- function(t) Imax * sin(pi * t / 12) # μmol m^-2 s^-1, daylight 0..12
Izt <- function(z,t) pmax(0, I0_t(t) * exp(-k*z))
Pg <- function(I) Pmax * (1 - exp(-alpha * I / Pmax)) # μmol O2 m^-2 h^-1
simpson_day <- function(z){
t <- c(0,3,6,9,12)
I <- Izt(z,t)
Pg_vals <- Pg(I) # already in μmol O2 m^-2 h^-1
# Simpson over hours (0..12)
h <- 3
integral <- (h/3) * (Pg_vals[1] + 4*Pg_vals[2] + 2*Pg_vals[3] + 4*Pg_vals[4] + Pg_vals[5])
return(list(t=t, I=I, Pg=Pg_vals, daytime_integral=integral))
}
day_surface <- simpson_day(0)
day_20m <- simpson_day(20)
day_surface$daytime_integral; day_20m$daytime_integral[1] 2952.021
[1] 1314.463
Daytime gross production: surface and 20 m are printed above (μmol O₂ m⁻² day⁻¹ over the 12 h light period).
24-h net production = daytime gross − \(24R\).
net0 net20
2424.0206 786.4627
Compensation depth: evaluate at 10, 20, 30 m and linearly interpolate where sign changes.
[1] 10 20 30
[1] 1836.34356 786.46268 47.42035
[1] NA
The printed zc is the estimated compensation depth for the given parameters. Increasing \(k\) to 0.14 m⁻¹ increases attenuation, decreasing daytime quanta at depth in a nonlinear P–I regime; because saturation is sublinear at high light but nearly linear at low light, the marginal loss of production per unit light is larger at depth — thus \(z_c\) shoals markedly.
# Sensitivity: k = 0.14
k <- 0.14
net24_k <- function(z){
Izt_k <- function(z,t) pmax(0, Imax * sin(pi*t/12) * exp(-k*z))
simpson_day_k <- function(z){
t <- c(0,3,6,9,12); h <- 3
I <- Izt_k(z,t)
Pg_vals <- Pmax * (1 - exp(-alpha * I / Pmax))
(h/3) * (Pg_vals[1] + 4*Pg_vals[2] + 2*Pg_vals[3] + 4*Pg_vals[4] + Pg_vals[5]) - 24*R
}
simpson_day_k(z)
}
z_vals2 <- c(10,15,20,25,30)
net_vals2 <- sapply(z_vals2, net24_k)
# locate sign change
idx2 <- which(diff(sign(net_vals2))!=0)
if(length(idx2)){
z1 <- z_vals2[idx2]; z2 <- z_vals2[idx2+1]
n1 <- net_vals2[idx2]; n2 <- net_vals2[idx2+1]
zc2 <- z1 + (0 - n1) * (z2 - z1) / (n2 - n1)
} else zc2 <- NA
list(net_at_depths=data.frame(z=z_vals2, net=net_vals2), zc_k014=zc2)$net_at_depths
z net
1 10 1417.2670
2 15 691.9574
3 20 158.7613
4 25 -164.1647
5 30 -341.3103
$zc_k014
[1] 22.45817
@online{smit,_a._j.,
author = {Smit, A. J., and for AJ, Prepared},
title = {Lab 2 — {Instructor’s} {Key} {(Worked} {Answers,} {R)}},
url = {http://tangledbank.netlify.app/BDC223/assessments/Lab2_Instructor_Key.html},
langid = {en}
}
---
title: "Lab 2 — Instructor's Key (Worked Answers, R)"
author: "Prepared for AJ"
format:
html:
toc: true
toc-depth: 3
code-fold: true
number-sections: true
execute:
echo: true
warning: false
message: false
---
This document provides fully worked solutions in **R** for Questions 1–11, with explicit unit handling and reproducible computations. Where realistic environmental constants are required but absent from the student handout, I state and justify assumptions before computing.
> **Notation**. `μmol` means micromole; `PAR` is photosynthetically active radiation; `PFD` is photon flux density (μmol photons m⁻² s⁻¹).
# Q1 — Dilutions (10 Marks)
A 1.5% (m:v) gel is 0.75 g per 50 mL (i.e. 1.5 g per 100 mL). You accidentally add 0.87 g to 50 mL.
**i. Percentage inadvertently prepared**
$$
\%\ \text{(m:v)}=\frac{0.87\ \text{g}}{50\ \text{mL}}\times 100\ \text{mL}=1.74\%\ .
$$
**ii. Extra water to add to reach 1.5%**
Solve $0.87\ \text{g}/V \times 100=1.5\Rightarrow V=58\ \text{mL}$. Current volume is 50 mL ⇒ add **8 mL**.
**iii–v. Short answers**
- _What is carrageenan?_ A sulfated galactan (polysaccharide) from **red algae** (Rhodophyta).
- _Role in plants?_ Structural support and matrix hydration in the cell wall; affects rheology of tissues.
- _Human uses?_ Gelling, thickening, stabilising agent in foods (e.g., dairy, processed meats) and in pharmaceuticals/cosmetics.
# Q2 — Quantum Light Measurements (4 Marks)
PFD $=120\ \mu\text{mol m}^{-2}\text{s}^{-1}$. Area $A=25\ \text{cm}^2=0.0025\ \text{m}^2$. Duration $T=2\ \text{h}=7200\ \text{s}$.
$$
\text{Quanta}=\text{PFD}\times A\times T\ .
$$
```{r code-navo-e23-mol}
NAvo <- 6.02214076e23 # mol^-1
pfd <- 120 # μmol m^-2 s^-1
A <- 25e-4 # m^2
Tsec <- 2*3600 # s
quanta_umol <- pfd * A * Tsec
photons <- quanta_umol * 1e-6 * NAvo # convert μmol -> mol -> photons
quanta_umol; photons
```
**Result.** $2160\ \mu\text{mol}$ ≈ $1.30\times 10^{21}$ photons.
# Q3 — Plant Growth Rates (9 Marks)
**Scenario i.** Biomass: 99 g (Day 1) → 149 g (Day 100). Interval Δt = 99 d.
Process: **absolute growth rate** (AGR).
```{r code-w0-w1-dt-days}
W0 <- 99; W1 <- 149; dt_days <- 99
AGR_g_d <- (W1 - W0)/dt_days
RGR_d <- (log(W1) - log(W0))/dt_days
AGR_g_d; RGR_d
```
AGR ≈ **0.505 g d⁻¹**. If asked, RGR ≈ **0.00439 g g⁻¹ d⁻¹**.
**Scenario ii.** O₂: 7.95 → 11.39 mg L⁻¹ in 20 min; algal biomass 2.3 g FM. Assume a 1 L chamber.
Process: **photosynthetic O₂ production rate** (normalized to biomass).
```{r code-o2-0-o2-1-dmin-biomass-g}
O2_0 <- 7.95; O2_1 <- 11.39; dmin <- 20; biomass_g <- 2.3
rate_mg_per_L_min <- (O2_1 - O2_0)/dmin
rate_mg_per_L_min_g <- rate_mg_per_L_min/biomass_g
rate_mg_per_L_h_g <- rate_mg_per_L_min_g * 60
rate_mg_per_L_min_g; rate_mg_per_L_h_g
```
Result: **0.0748 mg O₂ L⁻¹ min⁻¹ g⁻¹** (≈ **4.49 mg O₂ L⁻¹ h⁻¹ g⁻¹**). Units are explicit per litre; scale by chamber volume if different.
# Q4 — Light Attenuation (15 Marks)
Use Beer–Lambert: $I(z)=I_0 e^{-k z}$. We assume representative $k$ values (coastal, turbid vs offshore, clear):
- Nearshore (1 km): $I_0=1213$, $k_1=0.25\ \text{m}^{-1}$.
- Offshore (20 km): $I_0=2166$, $k_2=0.08\ \text{m}^{-1}$.
Compute profiles at 5 m steps to 50 m and plot.
```{r fig-depths-seq-by}
depths <- seq(0, 50, by=5)
I0_near <- 1213; k1 <- 0.25
I0_off <- 2166; k2 <- 0.08
I_near <- I0_near * exp(-k1 * depths)
I_off <- I0_off * exp(-k2 * depths)
plot(depths, I_near, type="o", ylim=range(c(I_near, I_off)),
xlab="Depth (m)", ylab="PFD (μmol m^-2 s^-1)", main="Vertical Light Profiles")
lines(depths, I_off, type="o")
legend("topright", legend=c("1 km (k=0.25)", "20 km (k=0.08)"), lty=1, pch=1:1)
```
**Comments.** Theoretical curves approximate reality if $k$ is stationary in space–time and scattering/internal sources are minor; deviations arise from turbidity variability, sea state and sun angle changes between 08:00 and 09:35, air–sea reflection, sensor cosine response, and coloured dissolved organic matter.
# Q5 — Photosynthetic Rate (10 Marks)
Leaf absorbs **10 μmol photons m⁻² s⁻¹**; quantum yield $=0.05\ \text{mol CO}_2\ \text{per mol photons}$.
$$
10\ \mu\text{mol photons s}^{-1}\times 0.05 = 0.5\ \mu\text{mol CO}_2\ \text{m}^{-2}\text{s}^{-1}\ .
$$
# Q6 — Relative Growth Rate (5 Marks)
$$
RGR=\frac{\ln(80)-\ln(50)}{10}\ .
$$
```{r code-rgr-log-log}
RGR <- (log(80)-log(50))/10
RGR
```
RGR ≈ **0.047 g g⁻¹ d⁻¹**. Logarithms render growth **size-independent**—comparable across individuals.
# Q7 — Respiration and Carbon Balance (5 Marks)
Daytime +15 mg CO₂ h⁻¹ for 12 h; nighttime −5 mg CO₂ h⁻¹ for 12 h.
```{r code-net}
net <- 12*15 - 12*5
net
```
Net over 24 h = **+120 mg CO₂ day⁻¹** (positive balance). If rates are per unit biomass, scale accordingly.
# Q8 — Additive Light Intensity at Depth (7 Marks)
Sum of components at 2 m: $400+120+50=570\ \mu\text{mol m}^{-2}\text{s}^{-1}$. The 500 μmol m⁻² s⁻¹ requirement **is met**. Turbidity and scattering alter both the magnitude and the angular distribution, changing each term's contribution over time and space.
# Q9 — Spectrally Resolved Attenuation and the 1% Level (12 Marks)
Surface PAR $I_0=1800$. Fractions: 45% at 490 nm with $k_{BG}=0.040\ \text{m}^{-1}$; 55% at 620 nm with $k_{RY}=0.25\ \text{m}^{-1}$.
$$
I(z)=0.45 I_0 e^{-0.040 z}+0.55 I_0 e^{-0.25 z}\ .
$$
Find $z_{1\%}$ such that $I(z_{1\%})=0.01 I_0$ (no closed form).
```{r fn-i0}
I0 <- 1800
k_BG <- 0.040; k_RY <- 0.25
I_light <- function(z) 0.45*I0*exp(-k_BG*z) + 0.55*I0*exp(-k_RY*z)
target <- 0.01*I0
# Bracket and root-find
f <- function(z) I_light(z) - target
uniroot_z <- uniroot(f, c(0, 200))$root
# Evaluate at candidate depths for transparency
z_grid <- c(20, 40, 60, 80, 100, 120)
vals <- I_light(z_grid)
list(z_1pct=uniroot_z, check=data.frame(z=z_grid, I=round(vals,1)))
```
At $z_{1\%}$ ≈ **91–92 m** (exact value printed above).
Fractional contribution of blue–green: $f_{BG}(z)=I_{BG}(z)/I(z)$.
```{r fn-i-bg-function-z-i0}
I_BG <- function(z) 0.45*I0*exp(-k_BG*z)
f_BG <- function(z) I_BG(z)/I_light(z)
f_30 <- f_BG(30); f_60 <- f_BG(60)
c(f_BG_30=f_30, f_BG_60=f_60)
```
Blue–green dominance **increases with depth** because the red–yellow band attenuates rapidly (higher $k$).
# Q10 — from Watts to Quanta; Integrating PAR (14 Marks)
Spectral energy irradiance (deck):
- $E=1.6\ \text{W m}^{-2}\text{nm}^{-1}$ over 400–500 nm; width 100 nm.
- $E=1.9\ \text{W m}^{-2}\text{nm}^{-1}$ over 500–700 nm; width 200 nm.
One photon at wavelength $\lambda$ has energy $E_{ph}(\lambda)=hc/\lambda$. Spectral photon irradiance:
$$
Q(\lambda)=\frac{E(\lambda)}{E_{ph}(\lambda)}\frac{1}{N_A}\times 10^6
=\frac{E(\lambda)\ \lambda}{h c}\cdot \frac{10^6}{N_A}\ .
$$
*(Unit check yields $\mu\text{mol m}^{-2}\text{s}^{-1}\text{nm}^{-1}$.)*
Compute piecewise-constant integrals using band midpoints for $\lambda$ (mean photon energy per band).
```{r code-h-e}
h <- 6.62607015e-34
c0 <- 2.99792458e8
NAvo <- 6.02214076e23
E1 <- 1.6 # W m^-2 nm^-1, 400-500
E2 <- 1.9 # W m^-2 nm^-1, 500-700
w1 <- 100 # nm
w2 <- 200 # nm
lambda1 <- 450e-9 # m (midpoint 400-500)
lambda2 <- 600e-9 # m (midpoint 500-700)
# spectral photon irradiance (μmol m^-2 s^-1 nm^-1)
Q1_spec <- (E1 * lambda1) / (h*c0) * (1e6/NAvo)
Q2_spec <- (E2 * lambda2) / (h*c0) * (1e6/NAvo)
Q_PAR_surface <- Q1_spec * w1 + Q2_spec * w2 # integrate over nm
Q1_spec; Q2_spec; Q_PAR_surface
```
Surface PAR ≈ **~ 2.36 × 10³–2.5 × 10³ μmol m⁻² s⁻¹** (exact value above).
Assuming depth-invariant attenuation $k=0.12\ \text{m}^{-1}$ and preserved spectral **shape** (amplitude only),
$$
Q(z)=Q(0)\,e^{-k z}\ .
$$
At $z=15\ \text{m}$:
```{r code-k-z}
k <- 0.12; z <- 15
Q_PAR_z <- Q_PAR_surface * exp(-k*z)
Q_PAR_z
```
**Note on the "shape preserved" assumption.** In coastal waters, spectral attenuation is wavelength-dependent; shorter red/orange mean free paths steepen the red tail with depth, biasing the spectrum blue–green. Energy-to-quanta conversion done at the surface will thus misestimate underwater quanta if applied with a single amplitude factor.
# Q11 — Daily Carbon Balance with Non-linear P–I (19 Marks)
Gross photosynthesis (Webb form, no inhibition):
$$
P_\text{gross}(I)=P_\text{max}\bigl(1-e^{-\alpha I/P_\text{max}}\bigr)\,,
$$
with $P_\text{max}=300$, $\alpha=0.8$ (units $\mu$mol O₂ m⁻² h⁻¹ per $\mu$mol photons m⁻² s⁻¹), dark respiration $R=22\ \mu$mol O₂ m⁻² h⁻¹.
Surface daylight half-sine (0–12 h): $I_0(t)=I_\text{max}\sin(\pi t/12)$, $I_\text{max}=2100$.
At depth: $I(z,t)=I_0(t)e^{-k z}$, $k=0.10\ \text{m}^{-1}$.
Use Simpson's rule over $t\in[0,12]$ with nodes $t=\{0,3,6,9,12\}$ h; convert seconds→hours where needed.
```{r fn-pmax}
Pmax <- 300
alpha <- 0.8
R <- 22 # μmol O2 m^-2 h^-1
Imax <- 2100
k <- 0.10
I0_t <- function(t) Imax * sin(pi * t / 12) # μmol m^-2 s^-1, daylight 0..12
Izt <- function(z,t) pmax(0, I0_t(t) * exp(-k*z))
Pg <- function(I) Pmax * (1 - exp(-alpha * I / Pmax)) # μmol O2 m^-2 h^-1
simpson_day <- function(z){
t <- c(0,3,6,9,12)
I <- Izt(z,t)
Pg_vals <- Pg(I) # already in μmol O2 m^-2 h^-1
# Simpson over hours (0..12)
h <- 3
integral <- (h/3) * (Pg_vals[1] + 4*Pg_vals[2] + 2*Pg_vals[3] + 4*Pg_vals[4] + Pg_vals[5])
return(list(t=t, I=I, Pg=Pg_vals, daytime_integral=integral))
}
day_surface <- simpson_day(0)
day_20m <- simpson_day(20)
day_surface$daytime_integral; day_20m$daytime_integral
```
**Daytime gross production**: surface and 20 m are printed above (μmol O₂ m⁻² day⁻¹ over the 12 h light period).
**24-h net production** = daytime gross − $24R$.
```{r fn-net24-function-z}
net24 <- function(z){
day <- simpson_day(z)$daytime_integral
net <- day - 24*R
net
}
net0 <- net24(0)
net20 <- net24(20)
c(net0=net0, net20=net20)
```
**Compensation depth**: evaluate at 10, 20, 30 m and linearly interpolate where sign changes.
```{r code-z-vals-c}
z_vals <- c(10,20,30)
net_vals <- sapply(z_vals, net24)
z_vals; net_vals
# Find interval containing zero and interpolate
idx <- which(diff(sign(net_vals))!=0)
if(length(idx)==0){
zc <- NA
} else {
z1 <- z_vals[idx]; z2 <- z_vals[idx+1]
n1 <- net_vals[idx]; n2 <- net_vals[idx+1]
zc <- z1 + (0 - n1) * (z2 - z1) / (n2 - n1)
}
zc
```
The printed `zc` is the estimated compensation depth for the given parameters. Increasing $k$ to 0.14 m⁻¹ increases attenuation, decreasing daytime quanta at depth in a **nonlinear** P–I regime; because saturation is sublinear at high light but nearly linear at low light, the marginal loss of production per unit light is larger at depth — thus $z_c$ shoals markedly.
```{r fn-k}
# Sensitivity: k = 0.14
k <- 0.14
net24_k <- function(z){
Izt_k <- function(z,t) pmax(0, Imax * sin(pi*t/12) * exp(-k*z))
simpson_day_k <- function(z){
t <- c(0,3,6,9,12); h <- 3
I <- Izt_k(z,t)
Pg_vals <- Pmax * (1 - exp(-alpha * I / Pmax))
(h/3) * (Pg_vals[1] + 4*Pg_vals[2] + 2*Pg_vals[3] + 4*Pg_vals[4] + Pg_vals[5]) - 24*R
}
simpson_day_k(z)
}
z_vals2 <- c(10,15,20,25,30)
net_vals2 <- sapply(z_vals2, net24_k)
# locate sign change
idx2 <- which(diff(sign(net_vals2))!=0)
if(length(idx2)){
z1 <- z_vals2[idx2]; z2 <- z_vals2[idx2+1]
n1 <- net_vals2[idx2]; n2 <- net_vals2[idx2+1]
zc2 <- z1 + (0 - n1) * (z2 - z1) / (n2 - n1)
} else zc2 <- NA
list(net_at_depths=data.frame(z=z_vals2, net=net_vals2), zc_k014=zc2)
```