ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Matlab® refresher Your objective: to dominate! My objective: to help you dominate!
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Some references MATLAB Student Version: Learning MATLAB, The MathWorks, Inc. Introduction to MATLAB 6 for Engineers, W.J.Palm III, McGraw-Hill. Numerical Methods with MATLAB, G.Recktenwald, Prentice Hall.
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Key concept: the Workspace (WS) The Workspace (WS) contains all of your currently active variables and relations. These are initially entered by typing commands (most likely). Useful Workspace commands: –Clear : empty the WS –Who (whos) : show what is in the WS –Save : save all WS variables to file –Load : retrieve a particular WS from file
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Key concept: WS inputs WORKSPACE
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Key concept: WS outputs WORKSPACE
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Script files Script files are text files that are created using the MATLAB script file editor. They usually have the suffix.m. A script file can be run from the command line or toolbar. Two items to remember about.m files: –Use “%” to enter comments for your use. –Use “;” at the end of lines to suppress echo printing when the file is run.
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY More about the Workspace Recording your MATLAB session can be useful for documentation. Useful Workspace commands: –Diary : turn on recording of all text i/o except plots, save into –Diary off : turn off current recording –Path : pointer to current directory –Pathtool : directory browser
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY A typical session pattern Clear Diary Problem1 { create data etc here …} –Pa= 14.7; R= 245.6; P= 23; Q = (1/R)*(P-Pa); –who Save Problem1Run1 Diary off You now have 2 files: Problem1: a diary of this session Problem1Run1: a WS file that can be used to recover your last state by using a Load command
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Solving Linear Algebraic Equations Define a set of linear algebraic equations as follows: A*X = B*U –X is the unknown vector (n x 1) –U is the input vector (m x 1) –A is n x n, B is n x m In the WS define A, B, and U. Then type X= inv(A)*B*U Click here to see an example session: LAExample1LAExample1
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Solving Linear Algebraic Equations Dominators know that a unique solution to a problem in linear algebra doesn’t always exist. To investigate before you leap try this: –Use the command det(A) to check the determinant of A. Proceed accordingly. Sometimes we seek insight in the form of eigenvalues of A. Try this: –Type Evals= eig(A). Click here to see an example session: LAExample2LAExample2
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Solving Linear Differential State Equations Define a set of linear algebraic equations: Xdot = A*X + B*U –Xdot is the first derivative of X. Create a script (.m) file that defines the equations for MATLAB in a specific format. –for example: LDEEqns1.m Create a script file that controls the solving of the problem. –click to see an example: LDEExample.pdfLDEExample.pdf