网站大量收购闲置独家精品文档,联系QQ:2885784924

MatLab – Palm Chapter 4, Part 3For and While Loops.ppt

  1. 1、本文档共28页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
MatLab – Palm Chapter 4, Part 3For and While Loops

4/5/2004 ENGR 111A - Spring 2004 MatLab – Palm Chapter 4, Part 3 For and While Loops Class 11.1 Palm Ch 4.5 RAT 11.1 As in INDIVIDUAL you have 2 minutes to answer the following question. What is the FINAL value assigned to y in the following segment of MATLAB code? x = 0; while x 5 y = sqrt(x); x = x + 1; end When asked, you have 30-seconds to submit your paper. Answer: y = 2 Learning Objectives Students should be able to: Understand Matlab iteration structures: for … end Loops while … end Loops Identify Implied loops Recognize these structures as repetition (or iteration) structures. Develop flow (logic) diagrams for combinations of branching and looping structures LOOPS A LOOP is a structure for repeating (iterating) a block of code. MATLAB uses two types of loops. for loop: number of passes known a priori (p. 210). while loop: loop terminates when a specified condition is satisfied (p. 221). for LOOPS SYNTAX: for k = start:step:stop block end start = initial value step = incremental value stop = terminating value See p. 212 for flowchart of for loop. for LOOP FLOW CHART EXAMPLE for k = 5:10:35 x = k^2 end for … end Loops (p. 211) for k = 5:10:35 x = k^2 end Means: starting with k = 5, execute the statements between for … end; then increment k by 10 and execute the statements with k = 15; etc. until k 35. Then exit the loop (k=? at this point) for … end Loops cont’d. Step value may be negative (default is positive 1) For step 0, loop does not execute if start stop For step 0, loop does not execute if start stop If start = stop, loop executes once Non-integer step values give unpredictable results (don’t use them!) INDIVIDUAL EXERCISE (5 min.) Evaluate xn = sin (np/10) for n between 1 and 10 (in increments of 1). Write a Matlab PROGRAM. (Plot x versus n) Save file on R:\ and name file after an historical figure. SOLUTION for n = 1:10 x(n) = sin(n*pi/10); end plot(1:10,x) % or plot(x) title(‘In-class… example’) xlabel(‘n’)

文档评论(0)

shaofang00 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档