机械设计方法 优化上机作业讲解 南京理工大学.pptVIP

  • 21
  • 0
  • 约3.62千字
  • 约 17页
  • 2017-11-30 发布于江西
  • 举报

机械设计方法 优化上机作业讲解 南京理工大学.ppt

机械设计方法 优化上机作业讲解 南京理工大学

机械优化设计 部分上机作业讲解 南京理工大学机械工程学院 梁医 * 1.进退法确定一维搜索空间; 1.进退法确定一维搜索空间 当初始点分别为x0=0及x0=1.8时,用进退法确定一维搜索空间,初始进退距h0=0.1 。 手工计算x0= 0 , [a,b]=[0.4,1.6] x0=1.8 ,[a,b]=[0.3,1.5] 第一步,画好程序框图; 第二步,边编程、边学习; 第三步,调试完成程序。 如图所示为教材上进退法的框图,现对此框图进行改进: 1.Matlab里面没有goto语句,因此用while替换掉goto; 2.将计算函数值的部分做成自定义函数程序。 第一步,画好程序框图 1.进退法确定一维搜索空间 While 语句 计算函数值 1.进退法确定一维搜索空间 第一步,画好程序框图 第二步,边学习,边编程; 1.进退法确定一维搜索空间 1)输入数据 a0=input(请输入初值=); h0=input(请输入初始步长=); user_entry = input(‘prompt’) displays ‘prompt’(提示) as a prompt on the screen, waits for input from the keyboard, and returns the value entered in user_entry. 需要学习: 输入数据、if、while、输出数据、自定义函数。 2)if语句 1.进退法确定一维搜索空间 第二步,边学习,边编程; If : Execute statements if condition is true Syntax : if expression, statements, end Description if expression, statements, end evaluates expression and, if the evaluation yields logical 1 (true) or a nonzero result, executes one or more MATLAB commands denoted here as statements. if expression1 statements1 elseif expression2 statements2 else statements3 end if f2f1 h0=-h0; a3=a1; f3=f1; a1=a2; f1=f2; a2=a3; f2=f3; a3=a2+h0; f3=f(a3); else a3=a2+h0; f3=f(a3); end 3)输出语句 1.进退法确定一维搜索空间 第二步,边学习,边编程; Disp:Display text or array Syntax :disp(X) Description disp(X) displays an array, without printing the array name. If X contains a text string, the string is displayed. Another way to display an array on the screen is to type its name, but this prints a leading X= which is not always desirable. Note that disp does not display empty arrays. a=min(a1,a3) b=max(a1,a3) ; disp(‘b=); disp(b); a=min(a1,a3) b=max(a1,a3) 语句后面不接分号,命令窗口将显示该行的运行结果。 另一方法: 1.进退法确定一维搜索空间 4)While 第二步,边学习,边编程; While : Repeatedly execute statements while condition is true Syntax :while expression, statements, end Description while expression, statements, end repeatedly executes one or more MATLAB statements in a loop, continuing until

文档评论(0)

1亿VIP精品文档

相关文档