[关闭]
@355073677 2016-03-19T23:30:57.000000Z 字数 4094 阅读 1371

Chapter 1 Problem 1.5


Name: Feng Chen
Student number: 2013301020145
March 19, 2016

Abstract

This is a programme to solve a specific first order ODE system via Euler method and store the datas in a txt file. Finally, I plotthe datas and compare this result to the analytical result. Also, I write a programme to read the datas in the .txt files to plot.

Introduction

This is a decay problem with two types of nuclei A ans B, which can decay into each other with the same time constant τ. The corresponding rate equations are:



Obviously, the number of these two types ( and ) of particles will reach a steady state. In such a steady state, the time derivative should vanish.

Nummerical Approach -- Euler method

Firstly, we do the Taylor expansion for the particle numbers N at time t :


When Δt is small enough, the error terms can be negligible.
Thus, the decay rate equations of particle A and B becomes:

Analytical Approcah

Firstly, we combine two rate equations:


Solving this equation, we get the function for particle A:

where C and D are two constant that determine by the initial conditions. If the initial number of particles are given, we can get the complete expressions.

In general, if the time constant of A is different with that of B, the results become:

where α is the ratio of time constant B and time constant A:

Data analysis

Setting the initial number of A is 100 and that of B is zero and the same time constant 1s.
Figure_1(0.05)Figure_1(0.01)
As the figures showed, when we make the time step smaller, the numerical result will be much more accurate. Also, due to the same time constant, the final number of both particles will be equal.

In general case, I set the different time constant for particel A and particle B. Sstting the initial number of A is 1000 and that of B is zero.
Figure_2
In this case the ratio of final number of B and A is equal to their time constant ratio. (For the particel number will reach the constant term in their expressions as time grows up.)

Finally, I add particle B at the initial time as well.
Figure_3

Read datas in the .txt file

In the previous programme, all the datas will be recorded in a .txt file and the format of datas are as follows:
Figure_4
As showed in the figure, the datas corresponding to the same time t are in the same row and each of them are seperated by a blank space.
Thus, we should transfer this data list into a 2-dimension list and each column is what we want.
The core codes are as follows:

  1. def read_initial(initial_file):
  2. itxt= open(initial_file)
  3. initial_data=[]
  4. data =[]
  5. for lines in itxt.readlines():
  6. lines=lines.replace("\n","").split(",")
  7. initial_data.append(lines)
  8. for i in range(len(initial_data[0][0].split(' '))):
  9. data.append([])
  10. for j in range(len(initial_data)):
  11. data[i].append(initial_data[j][0].split(' ')[i])
  12. itxt.close()
  13. return data ### data[0] = x, data[1] = y1, data[2] = y2,...

After transferring the data into a 2D list, we can plot the number of particles versus time:
Figure_6

Conclusion

In this project, we can learn how to use Euler method to solve simple first order ordinary differential equation or equations. On the other hand, all the high order differential equation can be transferred into equation systems, which means Euler method is also a way to solve high order differential equation.

Programme codes

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注