


全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
%function chain,state=markov(T,n,s0,V);%function chain,state=markov(T,n,s0,V);% chain generates a simulation from a Markov chain of dimension% the size of T% T is transition matrix% n is number of periods to simulate% s0 is initial state (initial probabilities)% V is the quantity corresponding to each state% state is a matrix recording the number of the realized state at time t% Original author: Tom Sargent% Comments added by Qiang Chenr c=size(T); % r is # of rows, c is # of columns of Tif nargin = 1; % nargin refers to number of arguments in. So only T is provided in this case V=1:r; s0=1; n=100;end;if nargin = 2; % both T and n are provided V=1:r; s0=1;end;if nargin = 3; % T, n and S0 are provided V=1:r;end;% check if the transition matrix T is squareif r = c; disp(error using markov function); disp(transition matrix must be square); return; % break the program and returnend;% check if each row of T sums up to 1for k=1:r; if sum(T(k,:) = 1; disp(error using markov function) disp(row ,num2str(k), does not sum to one); % num2str converts numbers to a string. disp( it sums to :); disp( sum(T(k,:) ); disp(normalizing row ,num2str(k),); T(k,:)=T(k,:)/sum(T(k,:); end;end;v1 v2=size(V);if v1 = 1 | v2 =r % | means or disp(error using markov function); disp(state value vector V must be 1 x ,num2str(r),) if v2 = 1 &v2 = r; disp(transposing state valuation vector); V=V; % change it to a column vector else; return; end; endif s0 r; disp(initial state ,num2str(s0), is out of range); disp(initial state defaulting to 1); s0=1;end;% The simulation of Markov chain formally starts from here%T%rand(uniform);X=rand(n-1,1); % generate (n-1) random numbers drawn from uniform distribution on 0,1, each number to be used in one simulation.s=zeros(r,1); % initiate the state vector s to be a rx1 zero vectors(s0)=1; % change the s0th element of s to 1cum=T*triu(ones(size(T); % triu(ones(size(T) generates an upper triangular matrix with all elements equal to 1% cum is a rxr matrix whose ith column is the cumulative sum from the 1st column to the ith column % the ith row of cum is the cumulative distribution for the next period given the current state. for k=1:length(X); % length(X) returns the size of the longest dimension of X. k indicates the kth simulation. state(:,k)=s; % state is a matrix recording the number of the realized state at time k ppi=0 s*cum; % this is the conditional cumulative distribution for the next period given the current state s s=(X(k)ppi(1:r); % compares each element of ppi(2:r+1) or ppi(1:r) with a scalar X(k), and % ret
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025“才聚齐鲁成就未来”山东建勘集团有限公司招聘68名笔试题库历年考点版附带答案详解
- 注射用盐酸万古霉素临床应用考核试题
- 2025广西河池市招聘中小学紧缺学科教师118人模拟试卷及答案详解(名师系列)
- 2025贵州遵义医科大学附属医院第十三届贵州人才博览会引进急需紧缺专业人才4人考前自测高频考点模拟试题完整参考答案详解
- 2025年浙能武威能源有限公司招聘模拟试卷及答案详解(考点梳理)
- 2025湖南长沙市雨花区砂子塘魅力第二小学储备教师招聘模拟试卷及答案详解一套
- 2025年甘肃省金昌市事业单位招聘笔试模拟试卷及答案详解(新)
- 2025蓝海新材料(通州湾)有限责任公司春季高校毕业生招聘45人模拟试卷及参考答案详解
- 2025年吉林省特岗教师招聘考试职位表考前自测高频考点模拟试题完整答案详解
- 2025甘肃交建中油能源有限责任公司加油(气)员招聘13人模拟试卷及答案详解(必刷)
- 管道热处理课件
- 纤维转盘滤布滤池运行维护技术说明
- 2025至2030中国无烟产品行业发展趋势分析与未来投资战略咨询研究报告
- 2021年全球工作场所状况报告 State of the Global Workplace 2021 Report
- 球墨铸铁管-施工方案(3篇)
- 小学音乐趣味教学讲座
- (正式版)DB35∕T 2242-2025 《户用光伏发电系统安装技术规范》
- 2025年职业技能鉴定考试(考评员)经典试题及答案
- 微创手术不育治疗-洞察及研究
- 屠宰场安全生产管理制度
- 盆腔超声诊断教学课件
评论
0/150
提交评论