Matlab: A Practical Introduction to Programming and Problem Solving
Format: PDF / Kindle (mobi) / ePub
MATLAB has become the standard software tool for solving scientific and engineering problems due to its powerful built-in functions and its ability to program. Assuming no knowledge of programming, this book guides the reader through both programming and built-in functions to easily exploit MATLAB's extensive capabilities for tackling engineering problems.
The book starts with programming concepts, such as variables, assignments, and selection statements, moves on to loops, and then solves problems using both the programming concept and the power of MATLAB. In-depth coverage is given to input/output, a topic fundamental to many engineering applications.
The third edition of MATLAB: A Practical Introduction to Programming and Problem Solving has been updated to reflect the functionality of the current version of MATLAB. It features new and revised end-of-chapter exercises, stronger coverage of loops and vectorizing, and more engineering applications to help the reader learn this software tool in context.
- Presents programming concepts and MATLAB built-in functions side-by-side
- Systematic, step-by-step approach, building on concepts throughout the book, facilitating easier learning
- Sections on common pitfalls and programming guidelines direct students towards best practice
has functions triu and tril that will take a matrix and make it into an upper triangular or lower triangular matrix by replacing the appropriate elements with 0′s. >> mymat mymat = >> triu(mymat) ans = >> tril(mymat) ans = Practice 11.2 For the following matrices: Which are equal? Which are square? For all square matrices, Calculate the trace. Which are symmetric? Which are diagonal? Which are lower triangular? Which are upper triangular? 11.1.3 Matrix
disp(‘It’’s a one!!’) case 3 disp(‘It’’s a three!!’) case 5 disp(‘It’’s a five!!’) otherwise disp(‘Follow directions next time!!’) end In this case, actions are taken if the user correctly enters one of the valid options. If the user does not, the otherwise clause handles printing an error message. Note the use of two single quotes within the string to print one. >> switcherror Enter a 1, 3, or 5: 4 Follow directions next time!! 3.6 The Menu Function MATLAB also has a
= ‘Engineering’; Then, get the length of each string. Create a new variable, v3, which is a substring of v2 that stores just ‘Engineer’. Create a matrix consisting of the values of v1 and v2 in separate rows. 6.2.2 Creating Customized Strings There are several built-in functions that create customized strings, including char, blanks, and sprintf. We have seen already that the char function can be used to convert from an ASCII code to a character, for example: >> char(97) ans = a
= ‘Smith, Carly’; ind = findstr(name,‘,’) first = name(1:ind-1) last = name(ind+2:end) [f rest] = strtok(name, ‘,’) l = rest(3:end) QUICK QUESTION! The function date returns the current date as a string; for example, ‘07-Feb-2008’. How could we write a function to return the day, month, and year as separate output arguments? Answer: We could use strrep to replace the ‘-’ characters with blanks, and then use strtok with the blank as the default delimiter to break up the string
Efficient Method QUICK QUESTION! The Programming Concept The Efficient Method The Efficient Method The Efficient Method The Programming Concept The Efficient Method The Programming Concept The Efficient Method QUICK QUESTION! 11.2 MATRIX SOLUTIONS TO SYSTEMS OF LINEAR ALGEBRAIC EQUATIONS The Programming Method The Efficient Method 11.3 SYMBOLIC MATHEMATICS Summary Exercises Chapter 12. Basic Statistics, Searching, and Sorting Key Words 12.1 Statistical Functions The