Solving a System of Differential Equations - A Step-by-Step Guide

Bill Foster
Messages
334
Reaction score
0

Homework Statement



I'm pretty rusty at these. But given the following:

\frac{dN_a}{dt}=-\frac{N_a}{\tau_a}
\frac{dN_b}{dt}=\frac{N_a}{\tau_a}-\frac{N_b}{\tau_b}

The Attempt at a Solution



The first one, naturally, is easy N_a(t)=N_a(0)e^\frac{-t}{\tau_a}

The second one is giving me a little trouble.

I tried it as such:

\frac{dN_b}{dt}=\frac{N_a\tau_b-N_b\tau_a}{\tau_a \tau_b}

\frac{dN_b}{N_a\tau_b-N_b\tau_a}=\frac{dt}{\tau_a \tau_b}

Let x=N_a\tau_b-N_b\tau_a

dx=-dN_b\tau_a

\frac{dx}{x\tau_a}=\frac{dt}{\tau_a \tau_b}

\frac{dx}{x}=\frac{dt}{\tau_b}

x(t)=x_0e^\frac{-t}{\tau_b}

N_a\tau_b-N_b\tau_a=x_0e^\frac{-t}{\tau_b}

N_b\tau_a=N_a\tau_b-x_0e^\frac{-t}{\tau_b}

N_b(t)=\frac{N_a\tau_b-x_0e^\frac{-t}{\tau_b}}{\tau_a}

Now, at t=0, N_b(t=0)=N_{b0}

So x_0=N_a\tau_b-N_{b0}\tau_a

N_b(t)=\frac{N_a\tau_b-(N_a\tau_b-N_{b0}\tau_a)e^\frac{-t}{\tau_b}}{\tau_a}

But I don't think that's right because it blows up. It's supposed to be a decay problem.

Did I solve it correctly?
 
Physics news on Phys.org
I believe that is right.

Now I'm trying to solve it using the Euler method...

N_b(t+\Delta{t})=N_b(t)-\Delta{t}*\frac{dN_b}{dt}

I get: N_b(t+\Delta{t})=N_b(t)-\Delta{t}*(\frac{N_a}{\tau_a}-\frac{N_b}{\tau_b})

And THAT blows up.
 
Bill Foster said:

Homework Statement



I'm pretty rusty at these. But given the following:

\frac{dN_a}{dt}=-\frac{N_a}{\tau_a}
\frac{dN_b}{dt}=\frac{N_a}{\tau_a}-\frac{N_b}{\tau_b}

The Attempt at a Solution



The first one, naturally, is easy N_a(t)=N_a(0)e^\frac{-t}{\tau_a}

The second one is giving me a little trouble.

I tried it as such:

\frac{dN_b}{dt}=\frac{N_a\tau_b-N_b\tau_a}{\tau_a \tau_b}
Instead use the solution to the first equation to write the equation as
\frac{dN_b}{dt}=\frac{N_a(0)}{\tau_a}e^\frac{-t}{\tau_a}-\frac{N_b}{\tau_b}
\frac{dN_b}{dt}+ \frac{N_b}{\tau_b}= \frac{N_a(0)}{\tau_a}e^\frac{-t}{\tau_a}

That's a linear non-homogeneous differential equation with constant coefficients. Its characteristic equation is r+ \frac{r}{\tau_b}= 0 and you can look for a specific solution of the entire equation of the form Ae^\frac{-t}{\tau_a}.

You will find that has solutions with decreasing exponentials.


\frac{dN_b}{N_a\tau_b-N_b\tau_a}=\frac{dt}{\tau_a \tau_b}

Let x=N_a\tau_b-N_b\tau_a

dx=-dN_b\tau_a

\frac{dx}{x\tau_a}=\frac{dt}{\tau_a \tau_b}

\frac{dx}{x}=\frac{dt}{\tau_b}

x(t)=x_0e^\frac{-t}{\tau_b}

N_a\tau_b-N_b\tau_a=x_0e^\frac{-t}{\tau_b}

N_b\tau_a=N_a\tau_b-x_0e^\frac{-t}{\tau_b}

N_b(t)=\frac{N_a\tau_b-x_0e^\frac{-t}{\tau_b}}{\tau_a}

Now, at t=0, N_b(t=0)=N_{b0}

So x_0=N_a\tau_b-N_{b0}\tau_a

N_b(t)=\frac{N_a\tau_b-(N_a\tau_b-N_{b0}\tau_a)e^\frac{-t}{\tau_b}}{\tau_a}

But I don't think that's right because it blows up. It's supposed to be a decay problem.

Did I solve it correctly?
 
Last edited by a moderator:
Finally got it right. I was right with my analytical solution, except for some sign errors. And it checks out with the Euler method solution. Here's a perl script that I wrote to test and illustrate:

Code:
#!/usr/bin/perl 

$dt=0.01;
$t=0;
$ta=1;
$tb=2;
$Na0=100;
$Nb0=0;
$Nae=$Na0;
$Nbe=$Nb0;
$i=0;
$imax=20;

for($i=0;$i<=$imax/$dt;$i++)
{
	$t=$i*$dt;
	$Na=$Na0*exp(-$t/$ta);
	$Nb=-($Na*$tb-($Na0*$tb+$Nb0*$ta)*exp(-$t/$tb))/$ta;
	if($i > 0)
	{
		$Nae=$Nae-$dt*$Nae/$ta;
		$Nbe=$Nbe+($Nae/$ta-$Nbe/$tb)*$dt;
	}
	printf("%f %f %f %f %f\n",$t,$Na,$Nae,$Nb,$Nbe);
}

Thanks for your input.
 
I guess it wasn't right. If I use different values for the decay constants my analytic solutions differs from the Euler solution.

HallsofIvy said:
Instead use the solution to the first equation to write the equation as
\frac{dN_b}{dt}=\frac{N_a(0)}{\tau_a}e^\frac{-t}{\tau_a}-\frac{N_b}{\tau_b}
\frac{dN_b}{dt}+ \frac{N_b}{\tau_b}= \frac{N_a(0)}{\tau_a}e^\frac{-t}{\tau_a}

That's a linear non-homogeneous differential equation with constant coefficients. Its characteristic equation is r+ \frac{r}{\tau_b}= 0 and you can look for a specific solution of the entire equation of the form Ae^\frac{-t}{\tau_a}.

You will find that has solutions with decreasing exponentials.

I don't know how to solve that.
 
The solution to the characteristic equation posted is the argument of an exponential e^{\frac{1}{\tau_{b}}}. This added with the particular solution of the form Ae^{\frac{-t}{\tau_{a}}} will give you your general solution.

Solving for the particular. Simply take the solution of the form Ae^{\frac{-t}{\tau_{a}}}, differentiate it, add them together and solve for the coefficients.

I'll get you started:

N = Ae^{\frac{-t}{\tau_a}}
N&#039;= \frac{-1}{\tau_{a}}Ae^{\frac{-t}{\tau_{a}}}

Sum them N&#039;+\frac{N}{\tau_{b}} = \frac{-1}{\tau_{a}}Ae^{\frac{-t}{\tau_{a}}}+\frac{1}{\tau_{b}}Ae^{\frac{-t}{\tau_{a}}}

Solve for coefficients A(\frac{-1}{\tau_{a}}+\frac{1}{\tau_{b}})= \frac{N_{a}(0)}{\tau_{b}} and
 
Last edited:
Bill Foster said:
I guess it wasn't right. If I use different values for the decay constants my analytic solutions differs from the Euler solution.



I don't know how to solve that.
What course is this for then? It is now a single non-homogeneous linear equation with constant coefficients. Much simpler than the original problem and much simpler than what you were trying to do.
 
HallsofIvy said:
What course is this for then? It is now a single non-homogeneous linear equation with constant coefficients. Much simpler than the original problem and much simpler than what you were trying to do.

Computational Physics.

The problem is to approximate the original system of differential equations using the Euler method, which I can do.

I am now trying to solve it analytically so I can compare it with the Euler solution.
 
Bill Foster said:
Computational Physics.

The problem is to approximate the original system of differential equations using the Euler method, which I can do.

I am now trying to solve it analytically so I can compare it with the Euler solution.

Take a look at how I solved it...
 
  • #10
Shouldn't it be : N = Ae^{\frac{-t}{\tau_b}}?
 
  • #11
No. Halls of Ivy showed you this result,

<br /> \frac{dN_b}{dt}=\frac{N_a(0)}{\tau_a}e^\frac{-t}{\tau_a}-\frac{N_b}{\tau_b}<br />

Which in turn becomes

<br /> \frac{dN_b}{dt}+ \frac{N_b}{\tau_b}= \frac{N_a(0)}{\tau_a}e^\frac{-t}{\tau_a}<br />

using this result, we get a non-homogeneous 2^{nd} order differentual equation with a particular solution Ae^{\frac{-t}{\tau_{a}}}

So we get a particular solution N_{p} = Ae^{\frac{-t}{\tau_{a}}}

then, N&#039;=\frac{-1}{\tau_{a}}Ae^{\frac{-t}{\tau_{a}}}

We sum the 2 with your coefficient: N&#039;+\frac{N}{\tau_{b}} = \frac{-1}{\tau_{a}}Ae^{\frac{-t}{\tau_{a}}}+\frac{1}{\tau_{b}}Ae^{\frac{-t}{\tau_{a}}}

Of course we solve for the coefficient A: A(\frac{-1}{\tau_{a}}+\frac{1}{\tau_{b}})= \frac{N_{a}(0)}{\tau_{b}}

Lets get a decent looking fraction first A(\frac{\tau_{a} - \tau_{b}}{\tau_{a} \tau_{b}})= \frac{N_{a}(0)}{\tau_{b}}

A = \frac{N_{a}(0)\tau_{a} \tau_{b}}{\tau_{b} (\tau_{a} - \tau_{b})}

N_{p}=\frac{N_{a}(0) \tau_{a} \tau_{b} e^{\frac{-t}{\tau_{a}}}}{\tau_{b} (\tau_{a} - \tau_{b})}
We have only solved the particular equation. Now we have to add it to the homogeneous equation.

The characteristic is as Ivy showed is r+ \frac{1}{\tau_b}= 0 Thus your N_{h} homogeneous is N_{h}= C_{1}e^{\frac{-t}{\tau_{b}}

Now summing them to get a general solution...N_{g}=N_{h}+N_{p} gives

N_{g}= C_{1} e^{\frac{-t}{\tau_{b}}} + \frac{N_{a}(0) \tau_{a} \tau_{b} }{\tau_{b} (\tau_{a} - \tau_{b})}e^{\frac{-t}{\tau_{a}}}

Now use your initial conditions to find C_1
 
Last edited:
  • #12
Well, that's quite a bit different than what I just got:

N_b(t)=[N_b(0)-\tau_aN_a(0)]e^{-\frac{t}{\tau_b}}-\tau_aN_a(0)e^{-\frac{t}{\tau_a}}

Hmmm
 
  • #13
djeitnstine said:
N_{g}= C_{1} e^{\frac{-t}{\tau_{b}}} + \frac{N_{a}(0) \tau_{a} \tau_{b} }{\tau_{b} (\tau_{a} - \tau_{b})}e^{\frac{-t}{\tau_{a}}}

Now use your initial conditions to find C_1

There's a problem with this. If \tau_a = \tau_b, it blows up.
 
  • #14
Bill Foster said:
There's a problem with this. If \tau_a = \tau_b, it blows up.

Yea cus division by 0 doesn't usually go well in math =\
 
  • #15
Oh man I got mixed up with all these tau sub a's and tau sub b's the final answer is
N_{g}= C_{1} e^{\frac{-t}{\tau_{b}}} + \frac{N_{a}(0) \tau_{a} \tau_{b} }{\tau_{a} (\tau_{a} - \tau_{b})}e^{\frac{-t}{\tau_{a}}}

(its the little \tau_{b} before the bracket in the denominator that's wrong)
 
  • #16
Final solution that matches the Euler solution:

N_b(t)=(N_b(0)-\frac{\tau_b}{\tau_a-\tau_b}N_a(0))e^{-\frac{t}{\tau_b}}+\frac{\tau_b}{\tau_a-\tau_b}N_a(0))e^{-\frac{t}{\tau_A}}

But what can I do about that condition when \tau_a=\tau_b?

The function should not blow up.
 
  • #17
Check that condition on your original DE, then compare that result with the actual answers. Basically check to see if any other solutions were lost.
 
Back
Top