• / 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条评论

还可以输入200字符

暂无评论,赶快抢占沙发吧。

关于本文
本文标题:matlab讲义5.ppt
链接地址:https://www.weizhuannet.com/p-7357043.html
微传网是一个办公文档、学习资料下载的在线文档分享平台!

微传网博客

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

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

copyright@ 2018-2028 微传网络工作室版权所有

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

收起
展开