# How to set up an equation to solve a rate law computationally?

I am confused on how to set up my equations to use in the solver. I have an equation
$$\ce{A + 2B -> C}$$
As a given, it is first order in A and second order in B. What I need to do is to solve for the concentrations of all three of $$\ce{A}$$, $$\ce{B}$$ and $$\ce{C}$$ using an ordinary differential equation (computationally in Matlab). The rate constant is given as $$\pu{8.5E-4}$$. I am given all initial concentrations ($$\pu{1.2 mol L-1}$$ for both).

To start off I have
$$r = k\ce{[A][B]2}$$ I have no idea where I should take this next, I feel completely lost here.

The second part of this is to do the same thing, but instead of being irreversible, the reaction is given as reversible.
$$\ce{A + 2B <=> C}$$ The concentrations are all given as are the forward and backward rate constants. Its first order in $$\ce{A}$$, 2nd in $$\ce{B}$$, and first in $$\ce{C}$$. $$\ce{[A]} = \pu{1.2 mol L-1}$$, $$\ce{[B]} = \pu{1.8 mol L-1}$$, $$\ce{[C]} = \pu{0.4 mol L-1}$$, $$k_\ce{for} = \pu{3.4E-2}$$, $$k_\ce{back} = \pu{1.2E-2}$$.

Again my initial thoughts are
$$r = \frac{k_\ce{for}}{k_{back}} \times \frac{\ce{[A][B]^{2}}}{\ce{[C]}}$$ But again I just don't know where to go next.

I hope I made my question understandable, if not I'll try to clarify anything. Any and all help would be appreciated, I really need it!

• See, you are in the company of people who know chemistry, but not necessarily Matlab. Do you know how to solve differential equations in Matlab (say, a simple one like $y'=-y$)? If you don't, then you have come to the wrong place. And if you do, what's stopping you from solving this one? – Ivan Neretin Feb 12 at 9:51
• I understand how to do the Matlab part of this (at least I think I do), but I do not understand how to get to an ODE from the reaction equation. I know how to use the correct functions in Matlab, but I don't really understand the chemistry of how to get there. In your example, I can solve y' = -y in Matlab, but what my question boils down to is how do I get to that type of equation from the reaction equation? – James Feb 12 at 10:29
• Wait, didn't you just write the rate expression ($r=\dots$)? – Ivan Neretin Feb 12 at 11:35

It should be set up as a series of first order ordinary differential equations like so: $$\frac{d[A]}{dt}=-k_f[A][B]^2+k_r[C]$$$$\frac{d[B]}{dt}=-2k_f[A][B]^2+2k_r[C]$$ $$\frac{d[C]}{dt}=k_f[A][B]^2-k_r[C]$$ If we substitute $$[C]=[C]_0+x$$, $$[A]=[A]_0-x$$, and $$[B]=[B]_0-2x$$ into these equations, they all reduce to the single equation:$$\frac{dx}{dt}=k_f([A]_0-x)([B]_0-2x)^2-k_r([C]_0+x)$$