同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 07 Sparse Arrays, Cell Arrays, and Structures

Sparse Arrays(1/35) 令a形 a=2*eye(10) a= 2 0 0 0 00 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 A sparse matrix is a large matrix in which the vast majority of the elements are zero. @日济大学 AW TONGJIUNIVERSITY
Sparse Arrays(1/35) a=2*eye(10) a = 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 A sparse matrix is a large matrix in which the vast majority of the elements are zero

Sparse Arrays(2/35) 令a b= 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 00 0 0 0 0 0 1 00 00 00 00 00 10 000 0 0 0 0 001 If these two matrices are multiplied together: c=a*b CPHAW @月协大学 TONGJI UNIVERSITY
Sparse Arrays(2/35) b = 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 If these two matrices are multiplied together: c=a*b

Sparse Arrays(3/35) C= 2 000 00 0000 0 40 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 10 0 00 0 0 00 00 0 2 0000 00 00 0 02000 0 00 0 0 002 00 0 000000020 00000 00002 The process of multiplying these two sparse matrices together requires 1900 multiplications and additions But the nonzero elements calculateonly 190 times---1/10 of the whole calculation @日济大学 AW TONGJIUNIVE具sITY
Sparse Arrays(3/35) C= 2 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 ✓ The process of multiplying these two sparse matrices together requires multiplications and additions. ✓ But the nonzero elements calculate only 190 times --- 1/10 of the whole calculation. 1900

Sparse Arrays(4/35) ▣The sparse data type The sparse data type actually saves three values for each nonzero element:the value of the element and the row and column numbers where the element is located. A=eye(2); sparse(A) ans= (1,1) 1 (2,2) 1 CDHAW @月协大学 TONGJI UNIVERSITY
Sparse Arrays(4/35) The sparse data type ✓ The sparse data type actually saves three values for each nonzero element: the value of the element and the row and column numbers where the element is located. ✓ A=eye(2); sparse(A) ans = (1,1) 1 (2,2) 1

Sparse Arrays(5/35) Common Matlab sparse matrix functions Category Function Description speye Create a sparse identity matrix Create Create a matrix containing uniformly sprand sparse distributed random values. matrices Create a matrix containing normally sprandn distributed random values. Full-to- sparse Convert a full matrix into a sparse matrix. sparse full Convert a sparse matrix into a full matrix. conversion functions find Find indices and values of nonzero elements in a matrix. 同濟大学 AW TONGJI UNIVERSITY
Sparse Arrays(5/35) Common Matlab sparse matrix functions Category Function Description Create sparse matrices speye Create a sparse identity matrix sprand Create a matrix containing uniformly distributed randomvalues. sprandn Create a matrix containing normally distributed randomvalues. Full-tosparse conversion functions sparse Convert a full matrix into a sparse matrix. full Convert a sparse matrix into a full matrix. find Find indices and values of nonzero elements in a matrix

Sparse Arrays(6/35) Example a-speye(4) full(a) a= ans (1,1) 1 1 0 0 0 (2,2) 1 0 1 00 (3,3) 1 0 01 0 (4,4) 1 00 01 r=sprand(s)has the same ¥[xyz]=find(a) sparsity structure as s X-y=Z- sprand(a) 1 1 1 ans 2 2 1 (1,1) 0.1341 3 3 1 (2,2) 0.0653 4 4 1 (3,3) 0.3751 细月济大学 (4,4) 0.3735 TONGJI UNIVERSITY
Sparse Arrays(6/35) Example ✓ a=speye(4) a = (1,1) 1 (2,2) 1 (3,3) 1 (4,4) 1 ✓ r = sprand(s) has the same sparsity structure as s ✓ sprand(a) ans = (1,1) 0.1341 (2,2) 0.0653 (3,3) 0.3751 (4,4) 0.3735 ✓ full(a) ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ✓ [x y z]=find(a) x = 1 2 3 4 y = 1 2 3 4 z = 1 1 1 1

Cell Arrays(7/35) A cell array is a special MATLAB array whose elements are cells,containers that can hold other MATLAB arrays. In programming terms,each element of a cell is a pointer to another data structure,and those structure can be of different types. For example,one cell ofa cell array might contain an array 3 of real numbers,another an array of strings,and yet another an array of complex numbers. @日济大学 AW TONGJI UNIVERSITY
Cell Arrays(7/35) A cell array is a special MATLAB array whose elements are cells, containers that can hold other MATLAB arrays. In programming terms, each element of a cell is a pointer to another data structure, and those structure can be of different types. For example, one cell of a cell array might contain an array of real numbers, another an array of strings, and yet another an array of complex numbers

Cell Arrays(8/35) Cell 1,1 Cell 1,2 「1 3 -7 3 4 'This is a text 9 -8 7 string!' Cell 2,1 Cell 2,2 「3+4i -5 -i10 3-i4 0 CPHAW 同你大学 TONGJI UNIVERSITY
Cell Arrays(8/35) Cell 1,1 Cell 1,2 ‘This is a text string!’ Cell 2,1 Cell 2,2 [] 1 3 7 2 3 4 9 8 7 − − 3 4 5 10 3 4 i i i + − − −

Cell Arrays(9/35) -7 2 3 4 9 -8 > Cell 1,1Cell 1,2 G 0 "This is a text string! Cell 2,1Cell 2,2 Q ○ 「3+4i-5 -103-4 Each element of a cell array holds a pointer to another data structure,and different cells in the same cell array can point to AW different types of data structures. 翻日济大学 TONGJI UNIVERSITY
Cell Arrays(9/35) Each element of a cell array holds a pointer to another data structure, and different cells in the same cell array can point to different types of data structures

Cell Arrays(10/35) ▣creating cell arrays √Two ways By using assignment statements. By preallocatinga cell array using the cell function Using assignment statements ■Content indexing a{1,1}=[13-7;206;051]; a{1,2)=This is a text string.'; a{2,1}=[3+4*i-5;-10*i3-4*i]: a{2,2}=[] ■Cell indexing a(1,1)={[13-7;206,051]}; a(1,2)={"This is a text string.); a(2,1)={[3+4*i-5;-10*i3-4*i]}; a(2,2)={[]}; @月协大学 TONGJI UNIVERSITY
Cell Arrays(10/35) creating cell arrays ✓ Two ways ◼ By using assignment statements. ◼ By preallocating a cell array using the cell function ✓ Using assignment statements ◼ Content indexing a{1,1}=[1 3 -7; 2 0 6;0 5 1]; a{1,2}='This is a text string.'; a{2,1}=[3+4*i -5; -10*i 3-4*i]; a{2,2}=[ ]; ◼ Cell indexing a(1,1)={[1 3 -7; 2 0 6;0 5 1]}; a(1,2)={'This is a text string.'}; a(2,1)={[3+4*i -5; -10*i 3-4*i]}; a(2,2)={[ ]};
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 06 User-defined Functions.ppt
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 05 Plotting.ppt
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 04 Branches and Loops.ppt
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 03Top-down and bottom-up design.ppt
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 02 MATLAB Basics(负责人:陈明).ppt
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 01 MATLAB Programming for Mechanical Engineering(Introduction to MATLAB).ppt
- 同济大学:《Matlab在机械设计中的应用》课程教学资源(试卷习题)Final Examination(B)The First Semester(2013-2014).pdf
- 同济大学:《Matlab在机械设计中的应用》课程教学资源(试卷习题)Final Examination(A)The First Semester(2013-2014).pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第6章 齿轮.pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第2章 平面机构的结构分析.pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第8章 其他常见机构.pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第9章 机械中的摩擦与效率.pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第5章 凸轮机构.pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第10章 机械的平衡.pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第7章 轮系(Gear Train).pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第3章 平面机构的运动分析(Kinematic Analysis).pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第4章 平面四杆机构.pdf
- 运城学院:《机械原理》课程教学资源(课件讲稿)第1章 绪论(负责人:倪娟).pdf
- 运城学院:《机械原理》课程教学资源(教案讲义)第1章 绪论(打印版).pdf
- 运城学院:《机械原理》课程教学资源(教案讲义)第9章 机械中的摩擦和效率.doc
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 08 Advanced Mathematics.ppt
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 09 Probability and statistics.ppt
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 10 Graphical User Interface.ppt
- 同济大学:《Matlab在机械设计中的应用》课程电子教案(PPT课件)Chapter 11 Simulink.pptx
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第一章 内燃机工作原理及总体构造 The Working Principles and Overall Structure of Internal Combustion Engines.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第二章 机体组及曲柄连杆机构 Engine Block, Crank and Connecting Rod Mechanism.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第三章 配气机构 Valve Trains(负责人:李理光).pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第四章 汽油机燃油供给系统 Fuel Supply System For Gasoline Engine.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第六章 进气、排气及增压系统 Intake, Exhaust and Boost Systems.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第五章 柴油机燃油供给系统 Fuel Supply System for Diesel Engines.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第七章 发动机冷却系 Cooling System.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第九章 起动系统 Starting System.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第八章 发动机润滑系 Lubrication System for Automotive Engines.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第十章 发动机点火系统 Engine Ignition System.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)第十二章 发动机有害排放物的控制系统 Control System of Harmful Emissions in Engine Exhaust.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)Automobile structure(Types of modern automobiles).pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)Chapter 13 传动系统 Overview of automobile drivetrain.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)Chapter 14 离合器 Clutch.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)Chapter 15 变速箱 Transmission and transfer case.pdf
- 同济大学:《汽车构造》课程电子教案(课件讲稿)Chapter 16 自动变速器 Vehicle Automatic transmission.pdf