1、Chapter 2Fundamentals of MATLABProgrammingSolving Applied Mathematical Problems with MATLABCRC/Taylor & Francis PressChinese version by Tsinghua University PressPPT by Wenbin Dong and Jun Peng, Northeastern University, PRCProofread by Dingyu Xue & YangQuan Chen 2019/3/6 Slide 1 (of 103)Chapter 2 Fun
2、damentals of MATLAB Programming Fundamentals of MATLAB Programming Fundamental Mathematical Calculations Flow Control Structures of MATLAB Language Writing and Debugging MATLAB Functions Two-dimensional Graphics Three-dimensional Graphics Chapter summary2019/3/6 Slide 2 (of 103) MATLAB has the follo
3、wing advantages:Clarity and high efficiencyScientific computation, covers almost all the useful topics in math and engineeringGraphics facilitiesComprehensive toolboxes and block-sets, designed by experts of almost all disciplines Powerful simulation facilities, unite the sub-systems of different do
4、mains together2019/3/6 Slide 3 (of 103)2.1 Fundamentals of MATLAB Programming Variables and constants in MATLAB Data structures Basic structure of MATLAB Colon expressions and sub-matrices extraction2019/3/6 Slide 4 (of 103)2.1.1 Variables and constants in MATLAB Variables in MATLABStarting with a l
5、etter followed by other characters:Case-sensitive:Valid variable names: MYvar12, MY_Var12 and MyVar12_Invalid variable names: 12MyVar, _MyVar12 Constants in MATLAB:eps, i, j, pi, NaN, Inf, i=sqrt(-1)lastwarn, lasterr2019/3/6 Slide 5 (of 103)2.1.2 Data structures Double-precision data type Symbolic d
6、ata type Other data types2019/3/6 Slide 6 (of 103)Double-precision data type IEEE standard, 64 bits (8 bytes), 11 bits for exponential and 53 bits for numerical and a sign bit. Use double() to convert other types to double. Data range: Other data types: int8(), int16(), int32(), uint16(), uint32()20
7、19/3/6 Slide 7 (of 103)Symbolic data type Usually used in formula derivations and analytical solutionsvariable declarationdisplay the symbolic variables in any precision The default value: 32 decimal digits.2019/3/6 Slide 8 (of 103)Example 2.1 Display the first 300 digits of . MATLAB command One may
8、 further increase the number of digits to display. For extremely large number of digits, process may be slow2019/3/6 Slide 9 (of 103)Other data types Strings:String variables are used to store messages. Multi-dimensional arrays:a direct extension of matrices with multiple indices. Cell arrays:to put a set of data of different types under a single variable, expressed by . Classes and objects:used in Object-Oriented Programming.2019/3/6 Slide 10 (of 103)