上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_recitation 14

Functions commands plot hold on meshc title hold off surf xlabel polar surfc ylabel bar surfl axis barh pcolor grid on pie shading faceted grid off plot3 shading flat legend meshgrid shading interp semilogx contour colormap semilogy contourf getframe loglog mesh movie color marker style line style y =yellow .point o=circle -=solid m=magenta x=x-mark +plus dotted c =cyan s=square d=diamond -.dash-dot r =red *star p=pentagram -dashed g green h=hexagram b =blue v triangle down w =white ^=triangle up k black >triangle right <triangle left tic/toc save/load
Functions & commands plot title xlabel ylabel axis grid on grid off legend semilogx semilogy loglog hold on hold off polar bar barh pie plot3 meshgrid contour contourf mesh meshc surf surfc surfl pcolor shading faceted shading flat shading interp colormap getframe movie tic/toc save/load

Example 1 function revolve(r1,r2,n) theta =0:pi/100:2*pi; x1 r1*cos(theta); y1 r1*sin(theta); range r1+2*r2; tic;号Starts the clock jj=1; for t 0:pi/50:2*pi center2x (r1+r2)*cos(t); center2y =(r1+r2)*sin(t); x2 =r2*cos (theta)+center2x; y2 =r2*sin(theta)+center2y; p1ot(x1,Y1,'r',x2,Y2,'b'); axis equal axis([-range range -range range]);axes always same mov(jj)=getframe; jj=jj+1; end time =toc;$Stores how long the program took to run fprintf('Time for preparation =$g\n',time); tic; movie(mov,n); time toc; fprintf('Time for playing =&g\n',time); return
Example 1 function revolve(r1,r2,n) theta = 0:pi/100:2*pi; x1 = r1*cos(theta); y1 = r1*sin(theta); range = r1+2*r2; tic; % Starts the clock jj = 1; for t = 0:pi/50:2*pi center2x = (r1+r2)*cos(t); center2y = (r1+r2)*sin(t); x2 = r2*cos(theta)+center2x; y2 = r2*sin(theta)+center2y; plot(x1,y1,'r',x2,y2,'b'); axis equal axis([-range range -range range]); % axes always same mov(jj) = getframe; jj = jj+1; end time =toc; % Stores how long the program took to run fprintf('Time for preparation = %g\n', time); tic; movie(mov,n); time = toc; fprintf('Time for playing = %g\n',time); return

Example 2 function cycloid(r,n) 号w=1rad/s theta =0:pi/100:2*pi; center y =r; cyc_x =[] cyc_y [] jj=1; for t 0:pi/30:n*2*pi center x =r*t; x =r*cos(theta)+center x; y =r*sin(theta)+center y; current x center x-r*sin(t); current y center_y-r*cos(t); cyc x [cye x,current x]; cye_y [cyc_y,current y]; plot (x,y,cyc_x,cyc_y,current x,current y,'rd'); axis equal axis ([-r,2*pi*r*n+r,0,3*r]) mov(jj)=getframe; jj=jj+1; end movie (mov) return
Example 2 function cycloid(r,n) % w=1rad/s theta = 0:pi/100:2*pi; center_y = r; cyc_x = []; cyc_y = []; jj = 1; for t = 0:pi/30:n*2*pi center_x = r*t; x = r*cos(theta) + center_x; y = r*sin(theta) + center_y; current_x = center_x-r*sin(t); current_y = center_y-r*cos(t); cyc_x = [cyc_x, current_x]; cyc_y = [cyc_y, current_y]; plot(x,y,cyc_x,cyc_y,current_x,current_y,'rd'); axis equal axis([-r,2*pi*r*n+r,0,3*r]) mov(jj) = getframe; jj = jj+1; end movie(mov) return

Example 3 function out combine(obj,n) if n==1 out obj(:); return end if n==length(obj) out obj; return end out [] for ii=1:length(obj)-n+1 first obj(ii); tail obj(ii+1:length (obj)); tail combinat combine(tail,n-1); loop out [first*ones (size(tail combinat,1),1), tail combinat]; out [out;loop out]; end ★Fibonacci Number ★Tower of Hanoi
Example 3 function out = combine(obj, n) if n==1 out = obj(:); return end if n==length(obj) out = obj; return end out = []; for ii = 1:length(obj)-n+1 first = obj(ii); tail = obj(ii+1:length(obj)); tail_combinat = combine(tail, n-1); loop_out = [first*ones(size(tail_combinat,1), 1), tail_combinat]; out = [out; loop_out]; end ★ Fibonacci Number ★ Tower of Hanoi
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_Recitation 11.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Other Resources_intrduction to computer and programming with C++ and MATLAB.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Assignments_assignment13.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Assignments_assignment12.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Assignments_assignment11.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Assignments_assignment 14.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Assignments_assignment 10_1.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Assignments_assignment 10.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_VIII.结构体与共用体.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_VII.指针.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_VI.编译预处理.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_V.数组.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_IX.文件.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_IV.函数和程序结构.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_III.流程控制.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_II.基本数据类型和运算.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C语言_I.C语言概述.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_VII.类与对象的高级操作.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_VI.类与对象.pdf
- 上海交通大学:《程序设计基础》课程教学资源(习题集)C++语言_V. 流库.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Sample Exam Questions_midterm 2 sample solution.pdf
- 上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Sample Exam Questions_Midterm 2008 sample.pdf
- 上海交通大学:《程序设计基础》课程教学资源(PPT课件讲稿)第1-2章 计算机简介、C++编程入门.ppt
- 上海交通大学:《程序设计基础》课程教学资源(PPT课件讲稿)第4-5章 控制结构.ppt
- 上海交通大学:《程序设计基础》课程教学资源(PPT课件讲稿)第6章 过程封装——函数.ppt
- 上海交通大学:《程序设计基础》课程教学资源(PPT课件讲稿)第7章 数组.ppt
- 上海交通大学:《程序设计基础》课程教学资源(PPT课件讲稿)第8章 间接访问——指针.ppt
- 上海交通大学:《程序设计基础》课程教学资源(PPT课件讲稿)第9章 数据封装——结构体.ppt
- 上海交通大学:《计算机硬件技术》课程PPT教学课件(计算机概论,孙德文).ppt
- 上海交通大学:《理论力学》课程教学资源(PPT讲稿)平面矢量.ppt
- 中华人民共和国国家标准(GB/T8567一2006 代替GB/T8567-1988)计算机软件文档编制规范 Specification for computer software documentation.pdf
- 《软件工程概论》课程教学资源(参考资料)Guide to the Software Engineering Body of Knowledge(SWEBOK)Version 3.0.pdf
- 《软件工程概论》课程教学资源(参考资料)软件工程知识体系指南(2004版).pdf
- 上海交通大学:《软件测试与质量控制》课程教学资源(课件讲稿)第1章 Introduction of software testing.pdf
- 上海交通大学:《软件测试与质量控制》课程教学资源(课件讲稿)第3章 Test environment and tools.pdf
- 上海交通大学:《软件测试与质量控制》课程教学资源(课件讲稿)第2章 Prerequisites Mathematics knowledge of software test.pdf
- 上海交通大学:《软件测试与质量控制》课程教学资源(课件讲稿)第4章 Fundamental theory and methods of software test.pdf
- 上海交通大学:《软件测试与质量控制》课程教学资源(课件讲稿)Chapter 2 fundamentals of software test.pdf
- 上海交通大学:《软件测试与质量控制》课程教学资源(课件讲稿)chapter 1 Introduction of software testing.pdf
- 上海交通大学:《软件测试与质量控制》课程教学资源(课件讲稿)教学大纲(高级软件测试).doc