- 1、本文档共40页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
系统仿真与MATLAB--广东工业大学自动化学院 第二部分 程序基本流程 Matlab 1 关系运算符和逻辑运算符 运算符 运算 == 等于 ~= 不等于 大于 = 大于或等于 小于 = 小于或等于 逻辑运算符 逻辑与 | 逻辑或 xor 逻辑与或 ~ 逻辑非 2 选择结构(分支语句) disp (This program solves for the roots of a quadratic ); disp (equation of the form A*X^2 + B*X + C = 0.); a = input(Enter the coefficient A: ); b = input(Enter the coefficient B: ); c = input(Enter the coefficient C: ); % Calculate discriminant discriminant = b^2 - 4 * a * c; if discriminant 0 % there are two real roots, so ... x1 = (-b + sqrt(discriminant)) / (2*a); x2 = (-b - sqrt(discriminant)) / (2*a); disp(This equation has two real roots:); fprintf(x1 = %f\n, x1); fprintf(x2 = %f\n, x2); else if discriminant == 0 % there is one repeated root, so ... x1 = ( -b ) / (2*a); disp(This equation has two identical real roots:); fprintf(x1 = x2 = %f\n, x1); else % there are complex roots, so ... real_part = (-b) / (2*a); imag_part = sqrt( abs(discriminant)) / (2*a); disp(This equation has complex roots:); fprintf(x1 = %f + i %f \n,real_part, imag_part); fprintf(x2 = %f - i %f \n, real_part, imag_part); end 2.switch语句 switch语句根据表达式的取值不同,分别执行不同的语句,其语句格式为: 【例】某商场对顾客所购买的商品实行打折销售,标准如下(商品价格用price来表示): price200 没有折扣 200≤price500 3%折扣 500≤price1000 5%折扣 1000≤price2500 8%折扣 2500≤price5000 10%折扣 5000≤price 14%折扣 输入所售商品的价格,求其实际销售价格。 程序如下: price=input(请输入商品价格); switch fix(price/100) case {0,1} %价格小于200 rate=0; case {2,3,4} %价格大于等于200但小于500 rate=3/100; case num2cell(5:9) %价格大于等于500但小于1000 rate=5/100; case num2cell(10:24) %价格大于等于1000但小于2500 rate=8/100; case num2cell(25:49) %价格大于等于2500但小于5000 rate=10/100; otherwise %价格大于等于5000 rate=14/100; end price=price*(1-rate)
文档评论(0)