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

• Bill Foster
In summary, the conversation discusses solving differential equations and specifically mentions a decay problem. The conversation covers the attempted solution using the Euler method and the correct analytical solution using the characteristic equation. The conversation also provides a perl script to test and illustrate the solutions.
Bill Foster

## 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?

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'= \frac{-1}{\tau_{a}}Ae^{\frac{-t}{\tau_{a}}}$$

Sum them $$N'+\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...

Shouldn't it be : $$N = Ae^{\frac{-t}{\tau_b}}$$?

No. Halls of Ivy showed you this result,

$$\frac{dN_b}{dt}=\frac{N_a(0)}{\tau_a}e^\frac{-t}{\tau_a}-\frac{N_b}{\tau_b}$$

Which in turn becomes

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

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'=\frac{-1}{\tau_{a}}Ae^{\frac{-t}{\tau_{a}}}$$

We sum the 2 with your coefficient: $$N'+\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:
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

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.

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 =\

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)

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.

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.

## 1. What is a system of differential equations?

A system of differential equations is a set of equations that describe the relationship between a set of variables and their rates of change. These equations are used to model dynamic systems in various fields such as physics, biology, and engineering.

## 2. Why is it important to solve a system of differential equations?

Solving a system of differential equations allows us to understand the behavior and predict the future state of a dynamic system. It is essential in many areas of science and engineering, such as studying population growth, predicting weather patterns, and designing control systems.

## 3. What is the process of solving a system of differential equations?

The process of solving a system of differential equations involves finding the values of the variables that satisfy all the equations in the system. This is usually done by using mathematical techniques such as separation of variables, substitution, or numerical methods.

## 4. What are the challenges in solving a system of differential equations?

One of the main challenges in solving a system of differential equations is finding an exact solution, which is often not possible for complex systems. Another challenge is choosing the appropriate method and ensuring accuracy in the solution. Additionally, some systems may have multiple solutions or no solutions at all.

## 5. How can I use the step-by-step guide to solve a system of differential equations?

The step-by-step guide provides a systematic approach to solving a system of differential equations. It outlines the necessary steps and provides examples for each step. By following the guide, you can learn how to set up and solve a system of differential equations using various methods, such as the elimination method or the substitution method.

Replies
1
Views
1K
Replies
3
Views
828
Replies
8
Views
2K
Replies
7
Views
844
Replies
1
Views
764
Replies
2
Views
609
Replies
6
Views
666
Replies
2
Views
908
Replies
12
Views
1K
Replies
7
Views
897