Skip to main content
Suggestion from comments!
Source Link
Metal Storm
  • 3.8k
  • 1
  • 4
  • 25

2. Function proposed For the equation you proposed, I think it has a mistake. Look that if $x \to \infty$ then $y \to 0$. We would like that as $x \to \infty$ then $y \to L$. So we just add a minus sign incan make two modifications regarding the exponential function $$ y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} \tag{3} $$horizontal asymptotes:

  • We would like that as $x \to \infty$ then $y \to L$. Thus, we add a minus sign in the exponential function.
  • We would like that as $x \to 0 $ then $y \to \beta \approx 2$. Thus, we add a constant term $\beta$ to the function.

Eq\begin{equation} y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} + \beta \tag{3} \end{equation} Eq. (3) has three parameters, $L$, $t_0$, and $k$. But I will follow your list and suppose that it has two parameters. From a practical point of view, it is clear that $L \approx 12$. This is a good decision because it diminishes by one the number of equations to be solved.

The partial derivatives of $y$ with respect to these two are immediate \begin{align} \frac{\partial y(t, \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t, \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}\begin{align} \frac{\partial y(t; \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t; \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}

3. Combining Now we combine Eq. (2) with Eq. (4) to get the first equation, and then Eq. (2) with Eq. (5) to get the second equation \begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} = 0 \tag{7} \end{align}\begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} - \beta\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} - \beta\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} &= 0 \tag{7} \end{align}

2. Function proposed For the equation you proposed, I think it has a mistake. Look that if $x \to \infty$ then $y \to 0$. We would like that as $x \to \infty$ then $y \to L$. So we just add a minus sign in the exponential function $$ y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} \tag{3} $$

Eq. (3) has three parameters, $L$, $t_0$, and $k$. But I will follow your list and suppose that it has two parameters. From a practical point of view, it is clear that $L \approx 12$. This is a good decision because it diminishes by one the number of equations to be solved.

The partial derivatives of $y$ with respect to these two are immediate \begin{align} \frac{\partial y(t, \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t, \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}

3. Combining Now we combine Eq. (2) with Eq. (4) to get the first equation, and then Eq. (2) with Eq. (5) to get the second equation \begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} = 0 \tag{7} \end{align}

2. Function proposed For the equation you proposed we can make two modifications regarding the horizontal asymptotes:

  • We would like that as $x \to \infty$ then $y \to L$. Thus, we add a minus sign in the exponential function.
  • We would like that as $x \to 0 $ then $y \to \beta \approx 2$. Thus, we add a constant term $\beta$ to the function.

\begin{equation} y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} + \beta \tag{3} \end{equation} Eq. (3) has three parameters, $L$, $t_0$, and $k$. But I will follow your list and suppose that it has two parameters. From a practical point of view, it is clear that $L \approx 12$. This is a good decision because it diminishes by one the number of equations to be solved.

The partial derivatives of $y$ with respect to these two are immediate \begin{align} \frac{\partial y(t; \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t; \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}

3. Combining Now we combine Eq. (2) with Eq. (4) to get the first equation, and then Eq. (2) with Eq. (5) to get the second equation \begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} - \beta\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} - \beta\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} &= 0 \tag{7} \end{align}

edited body
Source Link
Metal Storm
  • 3.8k
  • 1
  • 4
  • 25

I am answering to the comment that you made to the @Buttonwood's great answer.

Clearly the $y$ values are the $\text{pH}$ of the solution and the $x$ values the volume of base added. If you don't mind, I will use $y$ as the independentdependent variable, and $t$ as the dependentindependent variable.


1. Set of equations Our objective is to minimize the error given by \begin{align} E(\mathbf{P}) &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})]^2 \tag{1} \\ \end{align} where $i$ refers to the $i$-th experimental data, $N$ the number of points you have, $\hat{y}(t_i)$ the experimental value at time $t_i$, and $y_i(t;\mathbf{P})$ the function that tries to minimize the error evaluated at time $t_i$. The locations $t_i$'s are known to us, but we want to find the vector $\mathbf{P}$ that globally minimizes Eq. (1).

It $E$ has a minimum, then the gradient of $E$ is zero at $\mathbf{P} = (P_1, P_2, ...,P_k,..., P_m)$. Hence \begin{align} \require{cancel} \frac{\partial E}{\partial P_k}(\mathbf{P}) &= \sum_{i = 1}^N 2[\hat{y}(t_i) - y(t_i;\mathbf{P})]\frac{\partial [\hat{y}(t_i) - y(t_i;\mathbf{P})]}{\partial P_k} \\ &= \sum_{i = 1}^N \cancel{2}[\hat{y}(t_i) - y(t_i;\mathbf{P})]\cancel{(-1)} \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \\ &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})] \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \tag{2} \\ \end{align} Eq. (2) can be written for the $m$ unknowns that form $\mathbf{P} \in \mathbf{R}^m$, that form a set of $m$ nonlinear equations.


2. Function proposed For the equation you proposed, I think it has a mistake. Look that if $x \to \infty$ then $y \to 0$. We would like that as $x \to \infty$ then $y \to L$. So we just add a minus sign in the exponential function $$ y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} \tag{3} $$

Eq. (3) has three parameters, $L$, $t_0$, and $k$. But I will follow your list and suppose that it has two parameters. From a practical point of view, it is clear that $L \approx 12$. This is a good decision because it diminishes by one the number of equations to be solved.

The partial derivatives of $y$ with respect to these two are immediate \begin{align} \frac{\partial y(t, \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t, \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}


3. Combining Now we combine Eq. (2) with Eq. (4) to get the first equation, and then Eq. (2) with Eq. (5) to get the second equation \begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} = 0 \tag{7} \end{align}


4. Solve Eqs. (6-7) are a set of 2 non-linear equations with two unknowns, emphasized in color blue. I count $20$ experimental points in the geogebra plot you posted, so each equation has $20$ terms. This is the starting point. Although they look fearsome, one immediate way is to use Microsoft Excel. Put aside two cells, one with an initial guess of $k$ and other with $t_0$, and the next $5$ columns:

  1. The first one has the volume of the base added.
  2. The second one has the $\text{pH}$ values.
  3. The third one has the function given by Eq. (3) evaluated at the rows of column 1.
  4. The fourth one has the derivative with respect to $k$ evaluated at the rows of column 1.
  5. The fifth one has the derivative with respect to $t_0$ evaluated at the rows of column 1.

Points 3-5 also will need the $k$ and $t_0$ you put in the cells apart. Combine these values with operations to have two final cells, each one is the value of Eqs. (6) and (7). Finally, use the solver tool to get the values of the unknowns. You set the objective function as Eq. (6) and add the restriction that Eq. (7) yields zero. The solve will vary its values to find a (hopefully) global minimum.

If you want further math just add in the comments, there are additional methods, like Gauss-Newton which can be programmed by yourself.

I am answering to the comment that you made to the @Buttonwood's great answer.

Clearly the $y$ values are the $\text{pH}$ of the solution and the $x$ values the volume of base added. If you don't mind, I will use $y$ as the independent variable, and $t$ as the dependent variable.


1. Set of equations Our objective is to minimize the error given by \begin{align} E(\mathbf{P}) &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})]^2 \tag{1} \\ \end{align} where $i$ refers to the $i$-th experimental data, $N$ the number of points you have, $\hat{y}(t_i)$ the experimental value at time $t_i$, and $y_i(t;\mathbf{P})$ the function that tries to minimize the error evaluated at time $t_i$. The locations $t_i$'s are known to us, but we want to find the vector $\mathbf{P}$ that globally minimizes Eq. (1).

It $E$ has a minimum, then the gradient of $E$ is zero at $\mathbf{P} = (P_1, P_2, ...,P_k,..., P_m)$. Hence \begin{align} \require{cancel} \frac{\partial E}{\partial P_k}(\mathbf{P}) &= \sum_{i = 1}^N 2[\hat{y}(t_i) - y(t_i;\mathbf{P})]\frac{\partial [\hat{y}(t_i) - y(t_i;\mathbf{P})]}{\partial P_k} \\ &= \sum_{i = 1}^N \cancel{2}[\hat{y}(t_i) - y(t_i;\mathbf{P})]\cancel{(-1)} \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \\ &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})] \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \tag{2} \\ \end{align} Eq. (2) can be written for the $m$ unknowns that form $\mathbf{P} \in \mathbf{R}^m$, that form a set of $m$ nonlinear equations.


2. Function proposed For the equation you proposed, I think it has a mistake. Look that if $x \to \infty$ then $y \to 0$. We would like that as $x \to \infty$ then $y \to L$. So we just add a minus sign in the exponential function $$ y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} \tag{3} $$

Eq. (3) has three parameters, $L$, $t_0$, and $k$. But I will follow your list and suppose that it has two parameters. From a practical point of view, it is clear that $L \approx 12$. This is a good decision because it diminishes by one the number of equations to be solved.

The partial derivatives of $y$ with respect to these two are immediate \begin{align} \frac{\partial y(t, \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t, \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}


3. Combining Now we combine Eq. (2) with Eq. (4) to get the first equation, and then Eq. (2) with Eq. (5) to get the second equation \begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} = 0 \tag{7} \end{align}


4. Solve Eqs. (6-7) are a set of 2 non-linear equations with two unknowns, emphasized in color blue. I count $20$ experimental points in the geogebra plot you posted, so each equation has $20$ terms. This is the starting point. Although they look fearsome, one immediate way is to use Microsoft Excel. Put aside two cells, one with an initial guess of $k$ and other with $t_0$, and the next $5$ columns:

  1. The first one has the volume of the base added.
  2. The second one has the $\text{pH}$ values.
  3. The third one has the function given by Eq. (3) evaluated at the rows of column 1.
  4. The fourth one has the derivative with respect to $k$ evaluated at the rows of column 1.
  5. The fifth one has the derivative with respect to $t_0$ evaluated at the rows of column 1.

Points 3-5 also will need the $k$ and $t_0$ you put in the cells apart. Combine these values with operations to have two final cells, each one is the value of Eqs. (6) and (7). Finally, use the solver tool to get the values of the unknowns. You set the objective function as Eq. (6) and add the restriction that Eq. (7) yields zero. The solve will vary its values to find a (hopefully) global minimum.

If you want further math just add in the comments, there are additional methods, like Gauss-Newton which can be programmed by yourself.

I am answering to the comment that you made to the @Buttonwood's great answer.

Clearly the $y$ values are the $\text{pH}$ of the solution and the $x$ values the volume of base added. If you don't mind, I will use $y$ as the dependent variable, and $t$ as the independent variable.


1. Set of equations Our objective is to minimize the error given by \begin{align} E(\mathbf{P}) &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})]^2 \tag{1} \\ \end{align} where $i$ refers to the $i$-th experimental data, $N$ the number of points you have, $\hat{y}(t_i)$ the experimental value at time $t_i$, and $y_i(t;\mathbf{P})$ the function that tries to minimize the error evaluated at time $t_i$. The locations $t_i$'s are known to us, but we want to find the vector $\mathbf{P}$ that globally minimizes Eq. (1).

It $E$ has a minimum, then the gradient of $E$ is zero at $\mathbf{P} = (P_1, P_2, ...,P_k,..., P_m)$. Hence \begin{align} \require{cancel} \frac{\partial E}{\partial P_k}(\mathbf{P}) &= \sum_{i = 1}^N 2[\hat{y}(t_i) - y(t_i;\mathbf{P})]\frac{\partial [\hat{y}(t_i) - y(t_i;\mathbf{P})]}{\partial P_k} \\ &= \sum_{i = 1}^N \cancel{2}[\hat{y}(t_i) - y(t_i;\mathbf{P})]\cancel{(-1)} \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \\ &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})] \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \tag{2} \\ \end{align} Eq. (2) can be written for the $m$ unknowns that form $\mathbf{P} \in \mathbf{R}^m$, that form a set of $m$ nonlinear equations.


2. Function proposed For the equation you proposed, I think it has a mistake. Look that if $x \to \infty$ then $y \to 0$. We would like that as $x \to \infty$ then $y \to L$. So we just add a minus sign in the exponential function $$ y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} \tag{3} $$

Eq. (3) has three parameters, $L$, $t_0$, and $k$. But I will follow your list and suppose that it has two parameters. From a practical point of view, it is clear that $L \approx 12$. This is a good decision because it diminishes by one the number of equations to be solved.

The partial derivatives of $y$ with respect to these two are immediate \begin{align} \frac{\partial y(t, \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t, \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}


3. Combining Now we combine Eq. (2) with Eq. (4) to get the first equation, and then Eq. (2) with Eq. (5) to get the second equation \begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} = 0 \tag{7} \end{align}


4. Solve Eqs. (6-7) are a set of 2 non-linear equations with two unknowns, emphasized in color blue. I count $20$ experimental points in the geogebra plot you posted, so each equation has $20$ terms. This is the starting point. Although they look fearsome, one immediate way is to use Microsoft Excel. Put aside two cells, one with an initial guess of $k$ and other with $t_0$, and the next $5$ columns:

  1. The first one has the volume of the base added.
  2. The second one has the $\text{pH}$ values.
  3. The third one has the function given by Eq. (3) evaluated at the rows of column 1.
  4. The fourth one has the derivative with respect to $k$ evaluated at the rows of column 1.
  5. The fifth one has the derivative with respect to $t_0$ evaluated at the rows of column 1.

Points 3-5 also will need the $k$ and $t_0$ you put in the cells apart. Combine these values with operations to have two final cells, each one is the value of Eqs. (6) and (7). Finally, use the solver tool to get the values of the unknowns. You set the objective function as Eq. (6) and add the restriction that Eq. (7) yields zero. The solve will vary its values to find a (hopefully) global minimum.

If you want further math just add in the comments, there are additional methods, like Gauss-Newton which can be programmed by yourself.

added 47 characters in body
Source Link
Metal Storm
  • 3.8k
  • 1
  • 4
  • 25

I am answering to the comment that you made to the @Buttonwood's great answer.

Clearly the $y$ values are the $\text{pH}$ of the solution and the $x$ values the volume of base added. If you don't mind, I will use $y$ as the independent variable, and $t$ as the dependent variable.


1. Set of equations Our objective is to minimize the error given by \begin{align} E(\mathbf{P}) &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})]^2 \tag{1} \\ \end{align} where $i$ refers to the $i$-th experimental data, $N$ the number of points you have, $\hat{y}(t_i)$ the experimental value at time $t_i$, and $y_i(t;\mathbf{P})$ the function that tries to minimize the error evaluated at time $t_i$. The locations $t_i$'s are known to us, but we want to find the vector $\mathbf{P}$ that globally minimizes Eq. (1).

It $E$ has a minimum, then the gradient of $E$ is zero at $\mathbf{P} = (P_1, P_2, ...,P_k,..., P_m)$. Hence \begin{align} \require{cancel} \frac{\partial E}{\partial P_k}(\mathbf{P}) &= \sum_{i = 1}^N 2[\hat{y}(t_i) - y(t_i;\mathbf{P})]\frac{\partial [\hat{y}(t_i) - y(t_i;\mathbf{P})]}{\partial P_k} \\ &= \sum_{i = 1}^N \cancel{2}[\hat{y}(t_i) - y(t_i;\mathbf{P})]\cancel{(-1)} \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \\ &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})] \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \tag{2} \\ \end{align} Eq. (2) must tocan be solvedwritten for the $m$ unknowns that form the vector $\mathbf{P}$$\mathbf{P} \in \mathbf{R}^m$, that form a set of $m$ nonlinear equations.


2. Function proposed For the equation you proposed, I think it has a mistake. Look that if $x \to \infty$ then $y \to 0$. We would like that as $x \to \infty$ then $y \to L$. So we just add a minus sign in the exponential function $$ y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} \tag{3} $$

Eq. (3) has three parameters, $L$, $t_0$, and $k$. But I will follow your list and suppose that it has two parameters. From a practical point of view, it is clear that $L \approx 12$. This is a good decision because it diminishes by one the number of equations to be solved.

The partial derivatives of $y$ with respect to these two are immediate \begin{align} \frac{\partial y(t, \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t, \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}


3. Combining Now we combine Eq. (2) with Eq. (4) to get the first equation, and then Eq. (2) with Eq. (5) to get the second equation \begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} = 0 \tag{7} \end{align}


4. Solve Eqs. (6-7) are a set of 2 non-linear equations with two unknowns, emphasized in color blue. I count $20$ experimental points in the geogebra plot you posted, so each equation has $20$ terms. This is the starting point. Although they look fearsome, one immediate way is to use Microsoft Excel. Put aside two cells, one with an initial guess of $k$ and other with $t_0$, and the next $5$ columns:

  1. The first one has the volume of the base added.
  2. The second one has the $\text{pH}$ values.
  3. The third one has the function given by Eq. (3) evaluated at the rows of column 1.
  4. The fourth one has the derivative with respect to $k$ evaluated at the rows of column 1.
  5. The fifth one has the derivative with respect to $t_0$ evaluated at the rows of column 1.

Points 3-5 also will need the $k$ and $t_0$ you put in the cells apart. Combine these values with operations to have two final cells, each one is the value of Eqs. (6) and (7). Finally, use the solver tool to get the values of the unknowns. You set the objective function as Eq. (6) and add the restriction that Eq. (7) yields zero. The solve will vary its values to find a (hopefully) global minimum.

If you want further math just add in the comments, there are additional methods, like Gauss-Newton which can be programmed by yourself.

I am answering to the comment that you made to the @Buttonwood's great answer.

Clearly the $y$ values are the $\text{pH}$ of the solution and the $x$ values the volume of base added. If you don't mind, I will use $y$ as the independent variable, and $t$ as the dependent variable.


1. Set of equations Our objective is to minimize the error given by \begin{align} E(\mathbf{P}) &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})]^2 \tag{1} \\ \end{align} where $i$ refers to the $i$-th experimental data, $N$ the number of points you have, $\hat{y}(t_i)$ the experimental value at time $t_i$, and $y_i(t;\mathbf{P})$ the function that tries to minimize the error evaluated at time $t_i$. The locations $t_i$'s are known to us, but we want to find the vector $\mathbf{P}$ that globally minimizes Eq. (1).

It $E$ has a minimum, then the gradient of $E$ is zero at $\mathbf{P} = (P_1, P_2, ...,P_k,..., P_m)$. Hence \begin{align} \require{cancel} \frac{\partial E}{\partial P_k}(\mathbf{P}) &= \sum_{i = 1}^N 2[\hat{y}(t_i) - y(t_i;\mathbf{P})]\frac{\partial [\hat{y}(t_i) - y(t_i;\mathbf{P})]}{\partial P_k} \\ &= \sum_{i = 1}^N \cancel{2}[\hat{y}(t_i) - y(t_i;\mathbf{P})]\cancel{(-1)} \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \\ &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})] \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \tag{2} \\ \end{align} Eq. (2) must to be solved for the $m$ unknowns that form the vector $\mathbf{P}$.


2. Function proposed For the equation you proposed, I think it has a mistake. Look that if $x \to \infty$ then $y \to 0$. We would like that as $x \to \infty$ then $y \to L$. So we just add a minus sign in the exponential function $$ y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} \tag{3} $$

Eq. (3) has three parameters, $L$, $t_0$, and $k$. But I will follow your list and suppose that it has two parameters. From a practical point of view, it is clear that $L \approx 12$. This is a good decision because it diminishes by one the number of equations to be solved.

The partial derivatives of $y$ with respect to these two are immediate \begin{align} \frac{\partial y(t, \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t, \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}


3. Combining Now we combine Eq. (2) with Eq. (4) to get the first equation, and then Eq. (2) with Eq. (5) to get the second equation \begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} = 0 \tag{7} \end{align}


4. Solve Eqs. (6-7) are a set of 2 non-linear equations with two unknowns, emphasized in color blue. I count $20$ experimental points in the geogebra plot you posted, so each equation has $20$ terms. This is the starting point. Although they look fearsome, one immediate way is to use Microsoft Excel. Put aside two cells, one with an initial guess of $k$ and other with $t_0$, and the next $5$ columns:

  1. The first one has the volume of the base added.
  2. The second one has the $\text{pH}$ values.
  3. The third one has the function given by Eq. (3) evaluated at the rows of column 1.
  4. The fourth one has the derivative with respect to $k$ evaluated at the rows of column 1.
  5. The fifth one has the derivative with respect to $t_0$ evaluated at the rows of column 1.

Points 3-5 also will need the $k$ and $t_0$ you put in the cells apart. Combine these values with operations to have two final cells, each one is the value of Eqs. (6) and (7). Finally, use the solver tool to get the values of the unknowns. You set the objective function as Eq. (6) and add the restriction that Eq. (7) yields zero. The solve will vary its values to find a (hopefully) global minimum.

If you want further math just add in the comments, there are additional methods, like Gauss-Newton which can be programmed by yourself.

I am answering to the comment that you made to the @Buttonwood's great answer.

Clearly the $y$ values are the $\text{pH}$ of the solution and the $x$ values the volume of base added. If you don't mind, I will use $y$ as the independent variable, and $t$ as the dependent variable.


1. Set of equations Our objective is to minimize the error given by \begin{align} E(\mathbf{P}) &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})]^2 \tag{1} \\ \end{align} where $i$ refers to the $i$-th experimental data, $N$ the number of points you have, $\hat{y}(t_i)$ the experimental value at time $t_i$, and $y_i(t;\mathbf{P})$ the function that tries to minimize the error evaluated at time $t_i$. The locations $t_i$'s are known to us, but we want to find the vector $\mathbf{P}$ that globally minimizes Eq. (1).

It $E$ has a minimum, then the gradient of $E$ is zero at $\mathbf{P} = (P_1, P_2, ...,P_k,..., P_m)$. Hence \begin{align} \require{cancel} \frac{\partial E}{\partial P_k}(\mathbf{P}) &= \sum_{i = 1}^N 2[\hat{y}(t_i) - y(t_i;\mathbf{P})]\frac{\partial [\hat{y}(t_i) - y(t_i;\mathbf{P})]}{\partial P_k} \\ &= \sum_{i = 1}^N \cancel{2}[\hat{y}(t_i) - y(t_i;\mathbf{P})]\cancel{(-1)} \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \\ &= \sum_{i = 1}^N [\hat{y}(t_i) - y(t_i;\mathbf{P})] \frac{\partial [y(t_i;\mathbf{P})]}{\partial P_k} = 0 \tag{2} \\ \end{align} Eq. (2) can be written for the $m$ unknowns that form $\mathbf{P} \in \mathbf{R}^m$, that form a set of $m$ nonlinear equations.


2. Function proposed For the equation you proposed, I think it has a mistake. Look that if $x \to \infty$ then $y \to 0$. We would like that as $x \to \infty$ then $y \to L$. So we just add a minus sign in the exponential function $$ y(t; \mathbf{P}) = \frac{L}{1 + \exp[\mathbf{-}k(t - t_0)]} \tag{3} $$

Eq. (3) has three parameters, $L$, $t_0$, and $k$. But I will follow your list and suppose that it has two parameters. From a practical point of view, it is clear that $L \approx 12$. This is a good decision because it diminishes by one the number of equations to be solved.

The partial derivatives of $y$ with respect to these two are immediate \begin{align} \frac{\partial y(t, \mathbf{P})}{\partial k} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-1)(t - t_0) \\ &= \frac{L\exp[-k(t - t_0)](t - t_0)}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{4} \\ \frac{\partial y(t, \mathbf{P})}{\partial t_0} &= -\frac{L}{\{1 + \exp[-k(t - t_0)]\}^2}\exp[-k(t - t_0)](-k)(-1) \\ &= -\frac{kL\exp[-k(t - t_0)]}{\{1 + \exp[-k(t - t_0)]\}^2} \tag{5} \end{align}


3. Combining Now we combine Eq. (2) with Eq. (4) to get the first equation, and then Eq. (2) with Eq. (5) to get the second equation \begin{align} \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} \frac{L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})](t_i - \color{blue}{t_0})} {\{1 + \exp[-\color{blue}{k}(t_i - t_0)]\}^2} &= 0 \tag{6} \\ \sum_{i = 1}^N \left\{\hat{y}(t_i) - \frac{L} {1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]}\right\} (-1)\frac{\color{blue}{k}L\exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]} {\{1 + \exp[-\color{blue}{k}(t_i - \color{blue}{t_0})]\}^2} = 0 \tag{7} \end{align}


4. Solve Eqs. (6-7) are a set of 2 non-linear equations with two unknowns, emphasized in color blue. I count $20$ experimental points in the geogebra plot you posted, so each equation has $20$ terms. This is the starting point. Although they look fearsome, one immediate way is to use Microsoft Excel. Put aside two cells, one with an initial guess of $k$ and other with $t_0$, and the next $5$ columns:

  1. The first one has the volume of the base added.
  2. The second one has the $\text{pH}$ values.
  3. The third one has the function given by Eq. (3) evaluated at the rows of column 1.
  4. The fourth one has the derivative with respect to $k$ evaluated at the rows of column 1.
  5. The fifth one has the derivative with respect to $t_0$ evaluated at the rows of column 1.

Points 3-5 also will need the $k$ and $t_0$ you put in the cells apart. Combine these values with operations to have two final cells, each one is the value of Eqs. (6) and (7). Finally, use the solver tool to get the values of the unknowns. You set the objective function as Eq. (6) and add the restriction that Eq. (7) yields zero. The solve will vary its values to find a (hopefully) global minimum.

If you want further math just add in the comments, there are additional methods, like Gauss-Newton which can be programmed by yourself.

added 6 characters in body
Source Link
Metal Storm
  • 3.8k
  • 1
  • 4
  • 25
Loading
deleted 24 characters in body
Source Link
Metal Storm
  • 3.8k
  • 1
  • 4
  • 25
Loading
deleted 24 characters in body
Source Link
Metal Storm
  • 3.8k
  • 1
  • 4
  • 25
Loading
Source Link
Metal Storm
  • 3.8k
  • 1
  • 4
  • 25
Loading