当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

中山大学:《Matlab计算与仿真技术》课程教学资源(PPT课件讲稿)第八讲 Matlab编程-ll

资源类别:文库,文档格式:PPT,文档页数:35,文件大小:416KB,团购合买
第八讲提纲 一、第七讲回顾 二、Matlab编程- 1.函数初识 2.控制语句 3.函数变量
点击下载完整版文档(PPT)

Matlab计算与仿真技术 第八讲: Matlab编程- ittp: //human-robot sysu. edu. cn/course 王国利 http://human-robot.sysuedu.cn 信息科学与技术学院 中山大学

王国利 信息科学与技术学院 中山大学 http://human-robot.sysu.edu.cn Matlab计算与仿真技术 第八讲: Matlab编程-II http://human-robot.sysu.edu.cn/course

Matlab计算与仿真 第八讲提纲 ■第七讲回顾 Matlab编程-Ⅱ 函数初识 控制语句 -函数变量 中山火學

Matlab计算与仿真 ◼ 第七讲回顾 ◼ Matlab编程-II - 函数初识 - 控制语句 - 函数变量 第八讲提纲

Matlab计算与仿真 第七讲回顾 ■程序的概念与结构 程序:数据结构+算法 结构:顺序选择循环 编程的环境和工具 m文件编辑器 ■m文件及函数 m文件:脚本文件/函数文件 函数:主函数/子函数/ 中山火學

Matlab计算与仿真 第七讲回顾 ◼ 程序的概念与结构 - 程序: 数据结构+算法 - 结构: 顺序/选择/循环 ◼ 编程的环境和工具 - m 文件编辑器 ◼ m 文件及函数 - m文件: 脚本文件/函数文件 - 函数: 主函数/子函数/…

Matlab计算与仿真 Matlab编程(续) m-函数及子函数实例 1: function[mean, stdev=stat(x)%主函数定义 2: STAT Interesting statistics 3: n length(x): %数据个数查询 4:mean=avg(x,n):%子函数调用 5: stdev sqrt(sum((-avg(x, n)). 2)/n) 6:%----- 7: function mean=avg(x,n)%子函数定义 8:‰ AVG subfunction 9:mean= sum(x)/n:%内嵌函数调用 中山火學

Matlab计算与仿真 Matlab编程 (续) - m-函数及子函数实例 1:function [mean,stdev] = stat(x) % 主函数定义 2:% STAT Interesting statistics. 3:n = length(x); % 数据个数查询 4:mean = avg(x,n); % 子函数调用 5:stdev = sqrt(sum((x-avg(x,n)).^2)/n); 6:%------------------------- 7:function mean = avg(x,n) % 子函数定义 8:%AVG subfunction 9:mean = sum(x)/n; %内嵌函数调用

Matlab计算与仿真 Matlab编程(续) 函数申明与定义 1: function [mean, stdev]= stat(x) 关键词输出=(子)函数名(输入) 7: function mean ava(x n 子函数调用 4: mean = avg(x, n); 中山火學

Matlab计算与仿真 Matlab编程 (续) - 函数申明与定义 1: function [mean,stdev] = stat(x) ↑ ↑ ↑ 关键词 输出 = (子)函数名 (输入) ↓ ↓ ↓ 7: function mean = avg(x,n) - 子函数调用 4: mean = avg(x,n);

Matlab计算与仿真 Matlab编程(续) 函数的输入输出 twosum m two inputs, no output threesum. m- three inputs, one output addmult. m -two inputs, two outputs 1: function twosum(x,y 2: twosum Add two matrices 3: and print the result X+ 中山火學

Matlab计算与仿真 Matlab编程 (续) - 函数的输入输出 twosum.m — two inputs, no output threesum.m — three inputs, one output addmult.m — two inputs, two outputs ---------------------------------------------- 1: function twosum(x,y) 2: % twosum Add two matrices 3: % and print the result 4: x+y

Matlab计算与仿真 Matlab编程(续) function s= threesum(x, y, z) 2: threesum Add three variables 3: and return the result 4:5=X+y+z; 1: function [s, P]=addmult(x,y) 2:% addmult Compute sum and product 3: of two matrices 4:s= 5 p=×"y 中山火學

Matlab计算与仿真 Matlab编程 (续) 1: function s = threesum(x,y,z) 2: % threesum Add three variables 3: % and return the result 4: s = x+y+z; --------------------------------------------- 1: function [s,p] = addmult(x,y) 2: % addmult Compute sum and product 3: % of two matrices 4: s = x+y; 5: p = x*y;

Matlab计算与仿真 Matlab编程(续) fosun的结果 >>twosum(2, 2) >A=[12:34] ans B=[56:78] > twosum(A, B) X=[12y=[34]:ans= > twosum(xy) 68 ans 1012 46 nosum(one,two)%将字符串转换成整数组 ans 227229212 中山火學

Matlab计算与仿真 Matlab编程 (续) twosum的结果 >> twosum(2,2) ans = 4 >> x = [1 2]; y = [3 4]; >> twosum(x,y) ans = 4 6 >> A = [1 2; 3 4]; >> B = [5 6; 7 8]; >> twosum(A,B); ans = 6 8 10 12 >> twosum(’one’,’two’) % 将字符串转换成整数组 ans = 227 229 212

Matlab计算与仿真 Matlab编程(续) fosun的结果(续) >> clear >>disp(Ix y) ×X=4y=-2 4-2 >>twosum(1,2)>>who ans your variables are ans X >×+y ans %注意Xy没有改变 中山火學

Matlab计算与仿真 twosum的结果(续) >> clear >> x = 4; y = -2; >> twosum(1,2) ans = 3 >> x+y ans = 2 Matlab编程 (续) >> disp([x y]) 4 -2 >> who Your variables are: ans x y % 注意: x,y 没有改变

Matlab计算与仿真 Matlab编程(续) threes运行结果 >>a= threesum(1, 2, 3) a 6 > threesum(4, 5,6) ans 15 > b= threesum (7, 8, 9) 注:b的值为24 中山火學

Matlab计算与仿真 - threesum运行结果 >> a = threesum(1,2,3) a = 6 >> threesum(4,5,6) ans = 15 >> b= threesum(7,8,9); 注:b的值为24 Matlab编程 (续)

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共35页,可试读12页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有