电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

isequal(mysort(A)

25页
  • 卖家[上传人]:ahu****ng1
  • 文档编号:146062337
  • 上传时间:2020-09-25
  • 文档格式:PPTX
  • 文档大小:403.74KB
  • / 25 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、IT1005,Lab session on week 9 (5th meeting),Good Friday and Happy Easter to all students,especially for those who understand the meaning and celebrate these events . Since Friday is a public holiday, students with lab sessions on Friday are advised to attend parallel lab sessions on the other days!,Lab 5 Quick Check,Have you all received my reply for lab 5? My reply should contains: Your M files Check your files for my comments, look for this tag “SH7: bla bla bla”. Use CTRL+F (Find feature) of y

      2、our text editor to quickly identify my SH7 tags. Your Microsoft Word file Only if you do not give me your M files. Most of my comments will be in the M files. Anyway, check my comments here, if any, especially for q1.c and q2.b. IMPORTANT: PLEASE DO NOT SEND ME DUPLICATE STUFFS!IF YOU SEND M FILES, DO NOT COPY THE CODE TO MS WORD FILE! Your marks is stored in the file “Marks.txt” inside the returned zip file! If there is something wrong with the marks, clarify it with me. Either under counting o

      3、r over counting. I have been quite lenient in the past few labs, next time I will be stricter.,L5.Q1.a: my_mean (standard),function theMean = my_mean(x) % let us name the input array as x. % if you want to explain something about this function, here is the best place! theSum = 0; % do not use name sum, as it is a default Matlab function name n = numel(x); for index = 1:n % sum everything from index 1 to last (note: there are other ways to do this loop) theSum = theSum + x(index); end theMean = t

      4、heSum / n; % return the average a.k.a. mean % Notice that we suppress ALL intermediate outputs with ;! % Our function should be clean!,L5.Q1.a: my_mean (geek),function theMean = my_mean(x) theMean = sum(x(:) / numel(x); % x(:) will give me an enumeration of the input array x (whatever dimension) into column vector % Doing x(:) will definitely give me a row vector % Thus, this trick will work for array of ANY dimension =) % sum will then work for this row vector. % Note that there is this line in

      5、 the lab 5 question 1.a. % You are NOT ALLOWED to use the MATLAB mean command, % and should instead use loops, etc (Matlab function sum is ok) to implement your function. % Very short, eh =).,L5.Q1.b: my_var (standard),function theVar = my_var(x) % We should just call our my_mean function here. Do not create it again (redundant!). % Store the result in a variable so that we do not re-count mean every time! (Important!) theMean = my_mean(x); n = numel(x); sumOfSD = 0; % sum of squared deviation!

      6、for index = 1:n % accumulate the sum of squared deviation sumOfSD = sumOfSD + (x(index) - theMean)2; end theVar = sumOfSD / (n-1); % you know why we divide this with n-1 right?,L5.Q1.b: my_var (geek),function theVar = my_var(x) theVar = sum(x(:) - my_mean(x) . 2) / (numel(x) - 1); % If you do not understand why that works, see these: % 1. Convert input array x into a row vector = x(:) % 2. Find the difference with the mean, scalar expansion! = x(:) - my_mean(x) % 3. Square the differences = (x(:

      7、) - my_mean(x) . 2 % 4. Sum the squared differences = sum(result of part 3 above) % 5. Divide the result in step 4 above with n 1,L5.Q1.c: (Crazy) Testing,% Many ways to do this, as long as you can show that your program is correct. % My way: There are mean and var commands in Matlab, let us compare with them THOROUGHLY! % mean and var(iance) are floating points, we must use floating point comparison! % Tests with MANY inputs, the best is to use random function :D, thorough test with minimum wor

      8、k for test = 1:100 % can increase this if you want :p, this is called stress test in Software Engineering A = randn(1,100); % just generate a big random array, every time the array is different result1 = abs(my_mean(A) - mean(A(:) eps); % CANNOT just say my_mean(A) - mean(A(:) ! result2 = abs(my_var(A) - var(A(:) eps); % We MUST test the ABSOLUTE difference! if result1 = 1 | result2 = 1 disp(sprintf(Test %d: WARNING, your program is still WRONG!, test); else disp(sprintf(Test %d: OK, test); end

      9、end,L5.Q1.d: Using randn,length = input(Enter the length of the random normalized array: ); arr = randn(1,length); % Random row array with mean near 0, variance near 1! theMean = my_mean(arr); theVar = my_var(arr); % Since the question wants the ans = to be printed, I use sprintf here! sprintf(The actual mean is %g and the actual variance is %g. Therefore the mean is off by %g, and the variance is off by %g., . theMean, theVar, abs(theMean), abs(theVar-1.0) % Do not write ; here! % for mean, you do not need to say abs(theMean-0), the -0 part is redundant,L5.Q2.a: my_sort.m (standard),function d = my_sort(x) % assume the input array x is a row vector d = x; % copy x to d first, d is the variable that holds our answer! n = numel(x); % as mentioned in lab hint. no change at all. for i = 1:n for j = 1:(n-1) if d(j) d(j+1) tmp = d(j); % need to store this in a temporary variable first d(j) = d(j+1); % otherwise the value of d(j) is gone after

      《isequal(mysort(A)》由会员ahu****ng1分享,可在线阅读,更多相关《isequal(mysort(A)》请在金锄头文库上搜索。

      点击阅读更多内容
    最新标签
    发车时刻表 长途客运 入党志愿书填写模板精品 庆祝建党101周年多体裁诗歌朗诵素材汇编10篇唯一微庆祝 智能家居系统本科论文 心得感悟 雁楠中学 20230513224122 2022 公安主题党日 部编版四年级第三单元综合性学习课件 机关事务中心2022年全面依法治区工作总结及来年工作安排 入党积极分子自我推荐 世界水日ppt 关于构建更高水平的全民健身公共服务体系的意见 空气单元分析 哈里德课件 2022年乡村振兴驻村工作计划 空气教材分析 五年级下册科学教材分析 退役军人事务局季度工作总结 集装箱房合同 2021年财务报表 2022年继续教育公需课 2022年公需课 2022年日历每月一张 名词性从句在写作中的应用 局域网技术与局域网组建 施工网格 薪资体系 运维实施方案 硫酸安全技术 柔韧训练 既有居住建筑节能改造技术规程 建筑工地疫情防控 大型工程技术风险 磷酸二氢钾 2022年小学三年级语文下册教学总结例文 少儿美术-小花 2022年环保倡议书模板六篇 2022年监理辞职报告精选 2022年畅想未来记叙文精品 企业信息化建设与管理课程实验指导书范本 草房子读后感-第1篇 小数乘整数教学PPT课件人教版五年级数学上册 2022年教师个人工作计划范本-工作计划 国学小名士经典诵读电视大赛观后感诵读经典传承美德 医疗质量管理制度 2 2022年小学体育教师学期工作总结 2022年家长会心得体会集合15篇
    关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
    手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
    ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.