Matlab数值计算最简单的一个例子——指数衰减
放射性衰变是指数衰减的典型例子。另外还有化学反应某反应物的减少,RC电路电流的减小,大气压随海拔高度的减小等。
指数衰减的方程:
\begin{equation}
\frac{dN(t)}{dt}=-\frac{N(t)}{\tau}
\label{eq1}
\end{equation}
其中,\(N(t)\)为\(t\)时刻的物理量\(N\),对于放射性衰变,\(N\)就是未衰变的原子核数目。\(\tau\)为时间常数。
方程\eqref{eq1}有解析解:
\]
这个解可以通过Matlab符号计算求得:
dsolve('DN=-N/tau')
ans =
C3*exp(-t/tau)
数值求解方程\eqref{eq1},可用欧拉格式将方程离散化。
\]
\]
将以上两式带入方程\eqref{eq1},得离散之后的方程:
\]
代入初始条件,即可得解。
下面写个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数值计算最简单的一个例子——指数衰减的更多相关文章
- 菜鸟学习Hibernate——简单的一个例子
一.Hibernate开发. 上篇博客已经为大家介绍了持久层框架的发展流程,持久层框架的种类. 为了能够使用Hibernate快速上手,我们先讲解一个简单的Hibernate应用实例hibernate ...
- struts2基础——最简单的一个例子
学习版本:struts-2.3.15.3 一.导入jar包,可以参考 官方项目 blank. 二.添加配置文件:web.xml struts.xml web.xml: <filter> & ...
- SSH整合最简单的一个例子
1.新建mysql数据库 create database spring; 切换数据库 use spring; 新建表 create table user (id int(3) auto_incre ...
- QT 自定义消息(超级简单的一个例子)
#define TEST_EVENT QEvent::User + 100 class CVxActuatorMain : public QMainWindow { protected: ...
- 写了个 Task.WhenAll(t)的一个例子。
public static void Main() { var t = Task.Run(() => { throw new Exception("aa"); }); Tas ...
- matlab实现梯度下降法(Gradient Descent)的一个例子
在此记录使用matlab作梯度下降法(GD)求函数极值的一个例子: 问题设定: 1. 我们有一个$n$个数据点,每个数据点是一个$d$维的向量,向量组成一个data矩阵$\mathbf{X}\in \ ...
- 一个简单的CORBA例子
因为对CORBA分析的需要,这里写一个简单的CORBA例子.从JDK1.2开始,JDK中集成了ORB的实现,本例子使用了JDK1.7,对于JDK1.2+应该都没有问题.这个例子实现一个简单的加减乘除的 ...
- 对Jena的简单理解和一个例子
本文简单介绍Jena(Jena 2.4),使用Protégé 3.1(不是最新版本)创建一个简单的生物(Creature)本体,然后参照Jena文档中的一个例子对本体进行简单的处理,输出本体中的Cla ...
- 轻松创建nodejs服务器(1):一个简单nodejs服务器例子
这篇文章主要介绍了一个简单nodejs服务器例子,本文实现了一个简单的hello world例子,并展示如何运行这个服务器,需要的朋友可以参考下 我们先来实现一个简单的例子,hello world ...
随机推荐
- php 读取文件的几种方法
文件操作的三个步骤,打开,操作,关闭.$fopen=fopen(路径,方式),fwrite($fopen,写入的字符串);fclose($fopen). 其中打开方式有如下几种方式: 模式 描述 r ...
- node的实践(项目一)
学习一门语言,我们先要学习他的基本的语法,基本的数据类型,基本的数组操作,字符串的操作,然后就是语言的特性,实现共享和降低耦合的方式,然后开始比较高级的学习(所有语言都是一样的),比如说通信方法,tc ...
- SQL修改表结构之添加主键,添加IDENTITY属性
设计一张表时没有考虑到主键Id及自增长,现又需要,原脚本: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[F ...
- 第二课:判断js变量的类型以及domReady的原理
1.类型的判断: js五种简单数据类型有:null,undefined,boolean,number,string. 还有复杂的数据类型:Object,Function,RegExp,Date,自定义 ...
- Spring学习进阶(一)初识Spring
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...
- 3.3.1实现Servlet
FirstServlet.java package com.helloweenvsfei.servlet; import java.io.IOException; import java.io.Pri ...
- 在Oracle里,表的别名不能用as,列的别名可以用as
列的别名也可以不用as,如:select t.a xxx from table t 在Oracle数据库中,数据表别名是不能加as的,例如: select a.appname from appinfo ...
- keep_on _coding——js_good_parts
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jeecms内容显示条数
1.按照1.2.3.4.5顺序显示 <div class="index-news"> [@cms_channel id='1'] <h2><span& ...
- easyui 动态修改窗口title
http://blog.csdn.net/liu251890347/article/details/39292307?utm_source=tuicool 使用easyui作为前台框架极大的节省了项目 ...