Matlab Mech Eee Lectures 1

Embed Size (px)

Citation preview

  • 1.Motivation How it is useful for: Summary Introduction to MATLAB A Layman Approach P Bharani Chandra Kumar([email protected])Department of Electrical EngineeringGMR Institute of TechnologyRajam, AP Lecture series on MATLABP Bharani Chandra Kumar

2. MotivationHow it is useful for:Summary Outline1 Motivation History of MATLAB Strengths of MATLAB Weakness of MATLAB 2 How it is useful for: Students Engineers/ ScientistsP Bharani Chandra Kumar 3. Motivation History of MATLABHow it is useful for: Strengths of MATLABSummary Weakness of MATLAB Outline1 Motivation History of MATLAB Strengths of MATLAB Weakness of MATLAB 2 How it is useful for: Students Engineers/ ScientistsP Bharani Chandra Kumar 4. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB stands for MATrix LABoratory. Developed primarily by Cleve Moler in the 1970s. Need student access to Fortran subroutines for solving linear (LINPACK) and eigenvalue (EISPACK) problems without requiring knowledge of Fortran . Developed as an interactive system to access LINPACK and EISPACK. Gained popularity primarily through word of mouth In the 1980s, MATLAB was rewritten in C with more functionality Mathworks, Inc. was created in 1984 is now responsible for development, sale, and support for MATLAB P Bharani Chandra Kumar 5. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB stands for MATrix LABoratory. Developed primarily by Cleve Moler in the 1970s. Need student access to Fortran subroutines for solving linear (LINPACK) and eigenvalue (EISPACK) problems without requiring knowledge of Fortran . Developed as an interactive system to access LINPACK and EISPACK. Gained popularity primarily through word of mouth In the 1980s, MATLAB was rewritten in C with more functionality Mathworks, Inc. was created in 1984 is now responsible for development, sale, and support for MATLAB P Bharani Chandra Kumar 6. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB stands for MATrix LABoratory. Developed primarily by Cleve Moler in the 1970s. Need student access to Fortran subroutines for solving linear (LINPACK) and eigenvalue (EISPACK) problems without requiring knowledge of Fortran . Developed as an interactive system to access LINPACK and EISPACK. Gained popularity primarily through word of mouth In the 1980s, MATLAB was rewritten in C with more functionality Mathworks, Inc. was created in 1984 is now responsible for development, sale, and support for MATLAB P Bharani Chandra Kumar 7. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB stands for MATrix LABoratory. Developed primarily by Cleve Moler in the 1970s. Need student access to Fortran subroutines for solving linear (LINPACK) and eigenvalue (EISPACK) problems without requiring knowledge of Fortran . Developed as an interactive system to access LINPACK and EISPACK. Gained popularity primarily through word of mouth In the 1980s, MATLAB was rewritten in C with more functionality Mathworks, Inc. was created in 1984 is now responsible for development, sale, and support for MATLAB P Bharani Chandra Kumar 8. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB stands for MATrix LABoratory. Developed primarily by Cleve Moler in the 1970s. Need student access to Fortran subroutines for solving linear (LINPACK) and eigenvalue (EISPACK) problems without requiring knowledge of Fortran . Developed as an interactive system to access LINPACK and EISPACK. Gained popularity primarily through word of mouth In the 1980s, MATLAB was rewritten in C with more functionality Mathworks, Inc. was created in 1984 is now responsible for development, sale, and support for MATLAB P Bharani Chandra Kumar 9. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB stands for MATrix LABoratory. Developed primarily by Cleve Moler in the 1970s. Need student access to Fortran subroutines for solving linear (LINPACK) and eigenvalue (EISPACK) problems without requiring knowledge of Fortran . Developed as an interactive system to access LINPACK and EISPACK. Gained popularity primarily through word of mouth In the 1980s, MATLAB was rewritten in C with more functionality Mathworks, Inc. was created in 1984 is now responsible for development, sale, and support for MATLAB P Bharani Chandra Kumar 10. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB stands for MATrix LABoratory. Developed primarily by Cleve Moler in the 1970s. Need student access to Fortran subroutines for solving linear (LINPACK) and eigenvalue (EISPACK) problems without requiring knowledge of Fortran . Developed as an interactive system to access LINPACK and EISPACK. Gained popularity primarily through word of mouth In the 1980s, MATLAB was rewritten in C with more functionality Mathworks, Inc. was created in 1984 is now responsible for development, sale, and support for MATLAB P Bharani Chandra Kumar 11. Motivation History of MATLABHow it is useful for: Strengths of MATLABSummary Weakness of MATLAB Outline1 Motivation History of MATLAB Strengths of MATLAB Weakness of MATLAB 2 How it is useful for: Students Engineers/ ScientistsP Bharani Chandra Kumar 12. Motivation History of MATLABHow it is useful for: Strengths of MATLABSummary Weakness of MATLAB MATLAB is relatively easy to learn MATLAB code is optimized to be relatively quick when performing matrix operations MATLAB may behave like a calculator or as a programming language MATLAB is interpreted, errors are easier to x Although primarily procedural, MATLAB does have some object-oriented elements.P Bharani Chandra Kumar 13. Motivation History of MATLABHow it is useful for: Strengths of MATLABSummary Weakness of MATLAB MATLAB is relatively easy to learn MATLAB code is optimized to be relatively quick when performing matrix operations MATLAB may behave like a calculator or as a programming language MATLAB is interpreted, errors are easier to x Although primarily procedural, MATLAB does have some object-oriented elements.P Bharani Chandra Kumar 14. Motivation History of MATLABHow it is useful for: Strengths of MATLABSummary Weakness of MATLAB MATLAB is relatively easy to learn MATLAB code is optimized to be relatively quick when performing matrix operations MATLAB may behave like a calculator or as a programming language MATLAB is interpreted, errors are easier to x Although primarily procedural, MATLAB does have some object-oriented elements.P Bharani Chandra Kumar 15. Motivation History of MATLABHow it is useful for: Strengths of MATLABSummary Weakness of MATLAB MATLAB is relatively easy to learn MATLAB code is optimized to be relatively quick when performing matrix operations MATLAB may behave like a calculator or as a programming language MATLAB is interpreted, errors are easier to x Although primarily procedural, MATLAB does have some object-oriented elements.P Bharani Chandra Kumar 16. Motivation History of MATLABHow it is useful for: Strengths of MATLABSummary Weakness of MATLAB MATLAB is relatively easy to learn MATLAB code is optimized to be relatively quick when performing matrix operations MATLAB may behave like a calculator or as a programming language MATLAB is interpreted, errors are easier to x Although primarily procedural, MATLAB does have some object-oriented elements.P Bharani Chandra Kumar 17. Motivation History of MATLABHow it is useful for: Strengths of MATLABSummary Weakness of MATLAB Outline1 Motivation History of MATLAB Strengths of MATLAB Weakness of MATLAB 2 How it is useful for: Students Engineers/ ScientistsP Bharani Chandra Kumar 18. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB is NOT a general purpose programming language MATLAB is an interpreted language (making it for the most part slower than a compiled language such as C++) MATLAB is designed for scientic computation and is not suitable for some things (such as parsing text) MATLAB is an interpreted language, slower than a compiled language such as C++ MATLAB commands are specic for MATLAB usage P Bharani Chandra Kumar 19. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB is NOT a general purpose programming language MATLAB is an interpreted language (making it for the most part slower than a compiled language such as C++) MATLAB is designed for scientic computation and is not suitable for some things (such as parsing text) MATLAB is an interpreted language, slower than a compiled language such as C++ MATLAB commands are specic for MATLAB usage P Bharani Chandra Kumar 20. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB is NOT a general purpose programming language MATLAB is an interpreted language (making it for the most part slower than a compiled language such as C++) MATLAB is designed for scientic computation and is not suitable for some things (such as parsing text) MATLAB is an interpreted language, slower than a compiled language such as C++ MATLAB commands are specic for MATLAB usage P Bharani Chandra Kumar 21. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB is NOT a general purpose programming language MATLAB is an interpreted language (making it for the most part slower than a compiled language such as C++) MATLAB is designed for scientic computation and is not suitable for some things (such as parsing text) MATLAB is an interpreted language, slower than a compiled language such as C++ MATLAB commands are specic for MATLAB usage P Bharani Chandra Kumar 22. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB is NOT a general purpose programming language MATLAB is an interpreted language (making it for the most part slower than a compiled language such as C++) MATLAB is designed for scientic computation and is not suitable for some things (such as parsing text) MATLAB is an interpreted language, slower than a compiled language such as C++ MATLAB commands are specic for MATLAB usage P Bharani Chandra Kumar 23. Motivation History of MATLAB How it is useful for: Strengths of MATLAB Summary Weakness of MATLAB MATLAB is NOT a general purpose programming language MATLAB is an interpreted language (making it for the most part slower than a compiled language such as C++) MATLAB is designed for scientic computation and is not suitable for some things (such as parsing text) MATLAB is an interpreted language, slower than a compiled language such as C++ MATLAB commands are specic for MATLAB usage P Bharani Chandra Kumar 24. MotivationStudentsHow it is useful for:Engineers/ ScientistsSummary Outline1 Motivation History of MATLAB Strengths of MATLAB Weakness of MATLAB 2 How it is useful for: Students Engineers/ ScientistsP Bharani Chandra Kumar 25. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for students: System dynamics can be analysed very easily Messy equations can be solved very easily Can enhance the skills required for present jobs Can do the projects in a very easy way Can be useful for analysis and study of multi-disciplinary research areas P Bharani Chandra Kumar 26. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for students: System dynamics can be analysed very easily Messy equations can be solved very easily Can enhance the skills required for present jobs Can do the projects in a very easy way Can be useful for analysis and study of multi-disciplinary research areas P Bharani Chandra Kumar 27. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for students: System dynamics can be analysed very easily Messy equations can be solved very easily Can enhance the skills required for present jobs Can do the projects in a very easy way Can be useful for analysis and study of multi-disciplinary research areas P Bharani Chandra Kumar 28. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for students: System dynamics can be analysed very easily Messy equations can be solved very easily Can enhance the skills required for present jobs Can do the projects in a very easy way Can be useful for analysis and study of multi-disciplinary research areas P Bharani Chandra Kumar 29. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for students: System dynamics can be analysed very easily Messy equations can be solved very easily Can enhance the skills required for present jobs Can do the projects in a very easy way Can be useful for analysis and study of multi-disciplinary research areas P Bharani Chandra Kumar 30. MotivationStudentsHow it is useful for:Engineers/ ScientistsSummary Outline1 Motivation History of MATLAB Strengths of MATLAB Weakness of MATLAB 2 How it is useful for: Students Engineers/ ScientistsP Bharani Chandra Kumar 31. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for Engineer/Scientists: Can do the research in various elds Contains various inbuilt blocks like electric power systems, IC engines, aircraft, process plant, etc . Need not required to struggle alot to get output as compared to other major packages Can compare the existing literature results using wide simulations Can be useful for analysis and study of multi-disciplinary research Can publish papers based on the simulations obtainedP Bharani Chandra Kumar 32. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for Engineer/Scientists: Can do the research in various elds Contains various inbuilt blocks like electric power systems, IC engines, aircraft, process plant, etc . Need not required to struggle alot to get output as compared to other major packages Can compare the existing literature results using wide simulations Can be useful for analysis and study of multi-disciplinary research Can publish papers based on the simulations obtainedP Bharani Chandra Kumar 33. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for Engineer/Scientists: Can do the research in various elds Contains various inbuilt blocks like electric power systems, IC engines, aircraft, process plant, etc . Need not required to struggle alot to get output as compared to other major packages Can compare the existing literature results using wide simulations Can be useful for analysis and study of multi-disciplinary research Can publish papers based on the simulations obtainedP Bharani Chandra Kumar 34. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for Engineer/Scientists: Can do the research in various elds Contains various inbuilt blocks like electric power systems, IC engines, aircraft, process plant, etc . Need not required to struggle alot to get output as compared to other major packages Can compare the existing literature results using wide simulations Can be useful for analysis and study of multi-disciplinary research Can publish papers based on the simulations obtainedP Bharani Chandra Kumar 35. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for Engineer/Scientists: Can do the research in various elds Contains various inbuilt blocks like electric power systems, IC engines, aircraft, process plant, etc . Need not required to struggle alot to get output as compared to other major packages Can compare the existing literature results using wide simulations Can be useful for analysis and study of multi-disciplinary research Can publish papers based on the simulations obtainedP Bharani Chandra Kumar 36. Motivation Students How it is useful for: Engineers/ Scientists Summary How it is useful for Engineer/Scientists: Can do the research in various elds Contains various inbuilt blocks like electric power systems, IC engines, aircraft, process plant, etc . Need not required to struggle alot to get output as compared to other major packages Can compare the existing literature results using wide simulations Can be useful for analysis and study of multi-disciplinary research Can publish papers based on the simulations obtainedP Bharani Chandra Kumar 37. MotivationHow it is useful for:Summary SummaryGeneral intro to MATLAB.History of MATLAB.Who and how it can be utilized!P Bharani Chandra Kumar 38. MotivationHow it is useful for:Summary SummaryGeneral intro to MATLAB.History of MATLAB.Who and how it can be utilized!P Bharani Chandra Kumar 39. MotivationHow it is useful for:Summary SummaryGeneral intro to MATLAB.History of MATLAB.Who and how it can be utilized!P Bharani Chandra Kumar 40. MotivationHow it is useful for:Summary SummaryGeneral intro to MATLAB.History of MATLAB.Who and how it can be utilized!P Bharani Chandra Kumar 41. AppendixFor Further ReadingFor Further Reading IRudra Pratap.Started with MATLAB : A Quick intro for Scientists andEngineers.Oxford University Press, 2006.www.mathworks.com P Bharani Chandra Kumar 42. Basics of MATLAB(Lecture 2)P Bharani Chandra [email protected] 43. MATLAB GUICommand Window WorkspaceCommand History [email protected] 44. Desktop ToolsCommand Window type commands Workspace view program variables clear to clear double click on a variable to see it in the Array Editor Command History view past commands save a whole session using diary [email protected] 45. Matrices A vector x = [1 2 5 1]x = 12 51 A matrix x = [1 2 3; 5 1 4; 3 2 -1]x = 123 514 32 -1 Transposey = x.y = 1 2 5 [email protected] 46. Matrices (Contd)Let, x= [ 1 2 35 1 43 2 -1]y = x(2,3) x(i,j) subscriptiony =4 whole rowy = x(3,:)y =32 -1y = x(:,2) whole columny = [email protected] 47. Operators (Arithmetic) + addition - subtraction * multiplication .*element-by-element mult / division ./element-by-element div ^ power.^element-by-element power complex conjugate.transpose transpose [email protected] 48. Operators (Relational, Logical) ==equal pi 3.14159265 ~=not equal j imaginary unit, 1 < less than i same as j greater than >=greater than or equal& AND | OR ~ [email protected] 49. Generating Vectors from functionsx = zeros(1,3) zeros(M,N) MxN matrix of zerosx = 00 0 ones(M,N)MxN matrix of ones x = ones(1,3) x = 111 rand(M,N)MxN matrix of uniformly x = rand(1,3)distributed random numberson (0,1) x = 0.9501 0.2311 [email protected] 50. Operators (in general) [ ] concatenation x = [ zeros(1,3) ones(1,2) ] x =0 0 0 1 1 ( ) subscriptionx = [ 1 3 5 7 9] x =1 3 5 7 9y = x(2) y =3 y = x(2:4) y =3 5 7 [email protected] 51. MATRIX OPERATIONS Let, A = eye(3)>> A = [ 10 001 000 1 ]>> eig(A)>> inv(A)>>A'>>A*Aans =ans =ans = ans =11 0 01 0 0 1 0 0 10 1 00 1 0 0 1 0 10 0 10 0 1 0 0 [email protected] 52. MATRIX OPERATIONS (Contd) Let,>> A = [1 2 3;4 5 6;7 8 9]A = [ 1 2 3 4 5 67 8 9 ]>> eig(A) >> B=A' >>C=A*B>> D=A.*Bans = B=C= D= 16.11681 4 7 14 32 501 8 21-1.11682 5 8 32 77 122 8 25 48-0.00003 6 9 50 122 19421 48 81 [email protected] 53. QUESTIONS ? [email protected] 54. Applications of MATLAB(Lecture 3)P Bharani Chandra [email protected] 55. OverviewLinear algebra Solving a linear equation Finding eigenvalues and eigenvectors Curve fitting and interpolationData analysis and statisticsNonlinear algebraic [email protected] 56. Linear Algebra Solving a linear system Find the values of x, y and z for the following equations:5x = 3y 2z +10 8y +4z = 3x + 20 2x + 4y - 9z = 9 Step 1: Rearrange equations: 5x - 3y + 2z = 10- 3x + 8y +4z = 202x + 4y - 9z = 9 Step 2: Write the equations in matrix form: [A] x = b 5 3 2 10 A = 3 8 4b = 20 2 4 9 9 [email protected] 57. Linear Algebra (Contd) Step 3: Solve the matrix equation in MATLAB:>> A = [ 5 -3 2; -3 8 4; 2 4 -9]; >> b = [10; 20; 9]>> x = A b x =3.4423.1982 1.1868 % Veification >> c = A*x >> c = 10.0000 20.0000 9.0000 [email protected] 58. Linear Algebra (Contd) Finding eigenvalues and eigenvectors Eigenvalue problem in scientific computations shows up as: Av=vThe problem is to find and v for a given A so that above eq. is satisfied:Method 1: Classical method by using pencil and paper: a) Finding eigenvalues from the determinant eqn.A I = 0b) Sole for n eigenvectors by substituting the corresponding eigenvalues in above eqn. [email protected] 59. Linear Algebra (Contd) Method 2: By using MATLAB:Step 1: Enter matrix A and type [V, D] = eig(A)>> A = [ 5 -3 2; -3 8 4; 2 4 -9]; >> [V, D] = eig(A) V = -0.1709 0.87290.4570-0.2365 0.4139 -0.8791 0.9565 0.2583 -0.1357 D =-10.34630 00 4.1693 000 [email protected] 60. Linear Algebra (Contd) Step 2: Extract what you need:V is an n x n matrix whose columns are eigenvectorsD is an n x n diagonal matrix that has the eigenvalues of A on its diagonal. [email protected] 61. Linear Algebra (Contd) Cross check: Let us check 2nd eigenvalue and second eigenvector will satisfy A v = v or not:v2=V(:,2) % 2nd column of V v2 = 0.8729 0.4139 0.2583>> lam2=D(2,2)% 2nd eigevalue lam2 = 4.1693 >> A*v2-lam2*v2 ans = 1.0e-014 * [email protected] 62. Curve Fitting What is curve fitting ? It is a technique of finding an algebraic relationship that best fits a given set of data. There is no magical function that can give you this relationship. You have to have an idea of what kind of relationship might exist between the input data (x) and output data (y).If you do not have a firm idea but you have data that you trust, MATLAB can help you to explore the best possible fit. [email protected] 63. Curve Fitting (Contd) Example 1 : straight line (linear) fit:x 510 20 50100Y 15 33 53 140 301Step 1: Plot raw data:Enter the data in MATLAB and plot it:>> x = [ 5 10 20 50 100];>> y = [15 33 53 140 301];>> plot (x,y,o)>> [email protected] 64. [email protected] 65. [email protected] 66. Curve Fitting (Contd) Example 2 : Comparing different fits: x = 0: pi/30 : pi/3y = sin(x) + rand (size(x))/100 Step 1: Plot raw data:>> plot (x,y,o)>> gridStep 2: Use basic fitting to do a quadratic and cubic fitStep 3 : Choose the best fit based on the [email protected] 67. [email protected] 68. InterpolationWhat is interpolation ?It is a technique of finding a functional relationship between variables such that a given set of discrete values of the variables satisfy that relationship.Usually, we get a finite set of data points from experiments. When we want to pass a smooth curve through these points or find some intermediate points, we use the technique of interpolation.Interpolation is NOT curve fitting, in that it requires the interpolated curve to pass through all the data points. Data can be interpolated using Splines or Hermite [email protected] 69. Interpolation (Contd) MATLAB providesthe following functions to facilitate interpolation:interp1 : One data interpolation i.e. given yi and xi, finds yj at desired xj from yj = f(xj).ynew = interp1(x,y,xnew, method) interp2 : Two dimensional data interpolation i.e. given zi at (xi,yi) from z = f(x,y). znew = interp2(x,y,z,xnew,ynew, method) interp3 : Three dimensional data interpolation i.e. given vi at (xi,yi,zi) from v = f(x,y,z). vnew = interp2(x,y,z,v,xnew,ynew,znew, method)spline : ynew = spline(x,y,xnew, method) [email protected] 70. Interpolation (Contd) Example:x = [123 4567 8 9] y = [1 4 9 16 25 36 49 6481] Find the value of 5.5?Method 1: Linear InterpolationMATLAB Command :>> yi=interp1(x,y,5.5,'linear') yi = 30.5000 [email protected] 71. Interpolation (Contd)Method 2: Cubic InterpolationMATLAB Command :>> yi =interp1(x,y,5.5,cubic')yi =30.2479 Method 3: Spline InterpolationMATLAB Command :>> yi =interp1(x,y,5.5,spline') Note: 5.5*5.5=yi =30.2500 [email protected] 72. Data Analysis and statistics It includes various tasks, such as finding mean, median, standard deviation, etc. MATLAB provides an easy graphical interface to do such type of tasks.As a first step, you should plot your data in the form you wish.Then go to the figure window and select data statistics from the tools menu.Any of the statistical measures can be seen by checking the appropriate [email protected] 73. Data Analysis and statistics (Contd)Example: x = [1 2 34 5 67 8 9]y = [14 91625 36 49 64 81] Find the minimum value, maximum value, mean, median? [email protected] 74. Data Analysis and statistics (Contd)[email protected] 75. Data Analysis and statistics (Contd)[email protected] 76. Data Analysis and statistics (Contd)[email protected] 77. Data Analysis and statistics (Contd) It can be performed directly by using MATLAB commands also:Consider: x = [1 2 3 4 5] mean (x) : Gives arithmetic mean of x or the avg. data. MATLAB usage: mean (x) gives 3.median (x) : gives the middle value or arithmetic mean of two middle Numbers. MATLAB usage: median (x) gives 3.Std(x): gives the standard deviationMax(x)/min(x): gives the largest/smallest [email protected] 78. Solving nonlinear algebraic equations Step 1: Write the equation in the standard form: f(x) = 0Step 2: Write a function that computes f(x).Step 3: Use the built-in function fzero to find the solution.Example 1: Solve sin x = e x 5 Solution: x= fzero('sin(x)-exp(x)+5',1) x [email protected] 79. Solving nonlinear algebraic equations(contd) Example 2: Solve x2 2x + 4 = 0Solution: x= fzero(x*x-2*x+4',1) x x=e sin = x [email protected] 80. QUESTIONS ? [email protected] 81. Optimization Techniquesthrough MATLAB (Lecture 4)P Bharani Chandra Kumar [email protected] 82. Overview Unconstrained OptimizationConstrained OptimizationConstrained Optimization through [email protected] 83. Why Optimize! Engineers are always interested in finding the best solution to the problem at hand Fastest Fuel Efficient Optimization theory allows engineers to accomplish this Often the solution may not be easily obtained In the past, it has been surrounded by certain [email protected] 84. The Greeks started it! Queen Dido of Carthage (7 century BC) Daughter of the king of Tyre Agreed to buy as much land asshe could enclose with onebulls hide Set out to choose the largestamount of land possible, withone border along the sea A semi-circle with side touching the ocean Founded Carthage Fell in love with Aeneas butcommitted suicide when he left. [email protected] 85. The Italians Countered Joseph Louis Lagrange (1736-1813) His work Mcanique Analytique (Analytical Mechanics) (1788) was a mathematical masterpiece Invented the method of variations which impressed Euler and became calculus of variations Invented the method ofmultipliers (Lagrange multipliers)Sensitivities of the performance index tochanges in states/constraints Became thefather ofLagrangian DynamicsEuler-Lagrange [email protected] 86. The Multi-Talented Mr. Euler Euler (1707-1783)Friend of LagrangePublished a treatise which becamethe de facto standard of thecalculus of variations The Method of Finding Curves that Show Some Property of Maximum or MinimumHe solved the brachistachrone(brachistos = shortest, chronos =time) problem very easily Minimum time path for a bead on a string, [email protected] 87. Hamilton and Jacobi William Hamilton (1805-1865)Inventor of the quaternion Karl Gustav Jacob Jacobi (1804- 1851)Discovered conjugate points inthe fields of extremalsGave an insightful treatment tothe second variation Jacobi criticized Hamiltons workHamilton-Jacobi equationBecame the basis of Bellmanswork 100 years later [email protected] 88. What to Optimize? Engineers intuitively know what they are interested in optimizingStraightforward problemsFuelTimePowerEffort More complexMaximum marginMinimum risk The mathematical quantity we optimize is called a cost function or performance index [email protected] 89. Optimization through MATLAB Consider initially the problem of finding a minimum to the function: MATLAB function FMINCON solves problems of the form:min F(X)subject to: A*X