放射性衰变是指数衰减的典型例子。另外还有化学反应某反应物的减少,RC电路电流的减小,大气压随海拔高度的减小等。

指数衰减的方程:

\begin{equation}

\frac{dN(t)}{dt}=-\frac{N(t)}{\tau}

\label{eq1}

\end{equation}

其中,\(N(t)\)为\(t\)时刻的物理量\(N\),对于放射性衰变,\(N\)就是未衰变的原子核数目。\(\tau\)为时间常数。

方程\eqref{eq1}有解析解:

\[N(t)=N(0)\exp(-t/\tau)
\]

这个解可以通过Matlab符号计算求得:

  dsolve('DN=-N/tau')
ans =
C3*exp(-t/tau)

数值求解方程\eqref{eq1},可用欧拉格式将方程离散化。

\[t_i=(i-1) \Delta t,\quad i=1,2,\dots,\mathrm{npoints}
\]

\[\frac{dN(t)}{dt}\approx\frac{N(t)-N(t-\Delta t)}{\Delta t}
\]

将以上两式带入方程\eqref{eq1},得离散之后的方程:

\[N(t_{i+1})=N(t_i)-N(t_i)\frac{\Delta t}{\tau}
\]

代入初始条件,即可得解。

下面写个Matlab 脚本文件,重复出Computational Physics_Giordano 2nd Edition的图1.1,pp11

%
% Exponent decay
% 'Computational Physics' book by N Giordano and H Nakanishi
% Section 1.2 p2
% Solve the Equation dN/dt = -N/tau
% by Joyful Physics Blog
% ------------------------------------------------------------ N_nuclei_initial = 100; %initial number of nuclei
npoints = 101; % Discretize time into 100 intervals
dt = 0.05; % set time step
tau=1; % set time constant
N_nuclei = zeros(npoints,1); % initializes N_nuclei, a vector of dimension npoints X 1,to being all zeros
time = zeros(npoints,1); % this initializes the vector time to being all zeros
N_nuclei(1) = N_nuclei_initial; % the initial condition, first entry in the vector N_nuclei is N_nuclei_initial
time(1) = 0; %Initialise time
for step=1:npoints-1 % loop over the timesteps and calculate the numerical solution
N_nuclei(step+1) = N_nuclei(step) - (N_nuclei(step)/tau)*dt;
time(step+1) = time(step) + dt;
end
% calculate analytical solution below
t=0:0.05:5;
N_analytical=N_nuclei_initial*exp(-t/tau);
% Plot both numerical and analytical solution
plot(time,N_nuclei,'ro',t,N_analytical,'b'); %plots the numerical solution in red and the analytical solution in blue
xlabel('Time (s)')
ylabel('Number of nuclei')
text(2,80,'Time constant = 1s')
text(2,70,'Time step = 0.05s')

运行程序,得到:

Matlab数值计算最简单的一个例子——指数衰减的更多相关文章

  1. 菜鸟学习Hibernate——简单的一个例子

    一.Hibernate开发. 上篇博客已经为大家介绍了持久层框架的发展流程,持久层框架的种类. 为了能够使用Hibernate快速上手,我们先讲解一个简单的Hibernate应用实例hibernate ...

  2. struts2基础——最简单的一个例子

    学习版本:struts-2.3.15.3 一.导入jar包,可以参考 官方项目 blank. 二.添加配置文件:web.xml struts.xml web.xml: <filter> & ...

  3. SSH整合最简单的一个例子

    1.新建mysql数据库   create database spring; 切换数据库 use spring; 新建表 create table user (id int(3) auto_incre ...

  4. QT 自定义消息(超级简单的一个例子)

    #define TEST_EVENT QEvent::User + 100   class CVxActuatorMain : public QMainWindow {   protected:    ...

  5. 写了个 Task.WhenAll(t)的一个例子。

    public static void Main() { var t = Task.Run(() => { throw new Exception("aa"); }); Tas ...

  6. matlab实现梯度下降法(Gradient Descent)的一个例子

    在此记录使用matlab作梯度下降法(GD)求函数极值的一个例子: 问题设定: 1. 我们有一个$n$个数据点,每个数据点是一个$d$维的向量,向量组成一个data矩阵$\mathbf{X}\in \ ...

  7. 一个简单的CORBA例子

    因为对CORBA分析的需要,这里写一个简单的CORBA例子.从JDK1.2开始,JDK中集成了ORB的实现,本例子使用了JDK1.7,对于JDK1.2+应该都没有问题.这个例子实现一个简单的加减乘除的 ...

  8. 对Jena的简单理解和一个例子

    本文简单介绍Jena(Jena 2.4),使用Protégé 3.1(不是最新版本)创建一个简单的生物(Creature)本体,然后参照Jena文档中的一个例子对本体进行简单的处理,输出本体中的Cla ...

  9. 轻松创建nodejs服务器(1):一个简单nodejs服务器例子

    这篇文章主要介绍了一个简单nodejs服务器例子,本文实现了一个简单的hello world例子,并展示如何运行这个服务器,需要的朋友可以参考下   我们先来实现一个简单的例子,hello world ...

随机推荐

  1. poj1082-Calendar Game-博弈/sg

    sg大法好 无脑sg即可,不用去找规律了. /*---------------------------------------------------------------------------- ...

  2. CAS ticket过期策略

    CAS提供可扩展的ticket过期策略,支持ticket-granting tickets (TGT)和service tickets (ST)的配置. CAS客户端存储用户信息一般使用session ...

  3. 我的权限系统设计实现MVC4 + WebAPI + EasyUI + Knockout(四)授权代码维护

    一.前言 权限系统设计中,授权代码是用来控制数据访问权限的.授权代码说白了只是一树型结构的数据,没有什么其它的业务意义.那么这个页面的功能也就非常简单授权代码维护:新增.修改.删除授权代码数据. 二. ...

  4. 集群之LVS(负载均衡)详解

    提高服务器响应能力的方法 scale on  在原有服务器的基础上进行升级或者直接换一台新的性能更高的服务器. scale out  横向扩展,将多台服务器并发向外响应客户端的请求.优点:成本低,扩展 ...

  5. easyui中tree控件添加自定义图标icon

    来源于:http://blog.163.com/lintianhuanhai@126/blog/static/165587366201421704420256/ <!DOCTYPE html&g ...

  6. ADHelper C#域用户操作(转)

    using System; using System.Collections.Generic; using System.DirectoryServices; using System.Linq; u ...

  7. zoj1665 dij变形

    既然输入的是损坏率,那1-x就是剩余的.最后只要剩余的最大. #include<stdio.h> #include<string.h> #define Max 99999999 ...

  8. ztree点击文字勾选checkbox,radio实现方法

    ztree的复选框checkbok,单选框radio是用背景图片来模拟的,所以点击文字即使用label括起checkbox,radio文字一起,点击文字也是无法勾选checkbox. 要想点击ztre ...

  9. jQuery 文本编辑器插件 HtmlBox 使用

    0.htmlbox下载地址:http://download.csdn.net/detail/leixiaohua1020/6376479 1.引入头文件 <script src="li ...

  10. 人工蜂群算法-python实现

    ABSIndividual.py import numpy as np import ObjFunction class ABSIndividual: ''' individual of artifi ...