• / 13
• 下载费用：10 金币

# matlab讲义5.ppt

matlab讲义5.ppt

Week 5,Relation and logical operators Controlling statements: for, while and if Generating Poisson Distribution,Relational and Logical Operators,Relational operators available , =, ==, ~=Logical operators to combine relational expressions: & (and), | (or), ~ (not)if ((b=a) & (b=c))disp(‘b is the maximum’) end,Control Statements,Matlab has three control constructs: for, while, if for is an iterated loop statement for i = 1:n … % loop body statements end or for i = m:s:n % from m to n in steps of s… end,a = rand(1,100); % sum a random vector s = 0; for i = 1:100 s = s+a(i); end % this can also be done by sum(a);,Example: for,% sum only the odd-index entries a = rand(100); s = 0; for i = 1:2:100 s = s+a(i); end,Example: for,A = zeros(k,k) % Hilbert matrix for m = 1:k for n = 1:k A(m,n) = 1/(m+n -1); end end,Example: for,% Matrix multiplication C = A*B for m = 1:k for n = 1:kfor j = 1:k C(m,n) = C(m,n) + A(m,j)*B(j,n);endend end,Example: for,while construct while …. end if construct if … else … (elseif ) (…) end,a = rand(1,100); % sum a random vector s = 0; j=1; while j 101s = s+a(j); j = j+1; end,Example: while,if A Bdisp(‘A is larger’)elseif A Bdisp(‘B is larger’)elseif A = = Bdisp(‘A equals B’)else disp(‘Unexpected situation’)end,Example: if,for j=1:class_sizeif score(j) = 90grade(j)=‘A’;elseif score(j) = 80grade(j)=‘B’;else grade(j)=‘F’;end end,Example: if,Generating Poisson Distribution,Set k=0 and P=1Generate a uniformly distributed random number Uk+1 and replace P by P*Uk+1If accept X = k, else k increases by one and return to Step 2,for i=1:N,k=0;p=1;u=rand;p=p*u;while p=exp(-lambda)u=rand;p=p*u;k=k+1;endx(i)=k; end,Or just use: poissrnd(lambda,M,N), 微传网所有资源均是用户自行上传分享，仅供网友学习交流，未经上传用户书面授权，请勿作他用。
0条评论

## 当前资源信息 hskm5268 ## 相关资源

• ## 质量部年度工作计划书.doc

• ## 质量管理体系过程矩阵表.doc

• ## 质点平动与刚体定轴转动规律的比较.doc

• ## 货物保价运输与货物运输保险的区别.doc

• ## 账户按用途和结构的分类.doc

• ## 谈谈当代大学生应该如何增强自身的公德意识.doc

• ## 谈谈大学体育课与高中体育课的区别.doc

• ## 谈谈你的情绪特点及影响.doc

• ## 谈企业与供应商的合作关系.doc

• ## 谈发动机起动困难故障 实训专题报告.doc

• 微传网博客

网站资源均来自网络，如有侵权，请联系客服删除！

网站客服QQ:80879498  会员QQ群：727456886

经营许可证编号：冀ICP备18006529号-1 ， 公安局备案号：13028102000124