Matlab Programming 1/24
2/24 What does MATLAB mean? Contraction of Matrix Laboratory Matrices are rectangular arrays of numerical values 7 3 6 2 1 9 4 4 8 4 1 5 7 2 1 3
What are the fundamental components of Matlab? Computing system that accepts one instruction at a time in text form Large library of modules that provide high-level capabilities for processing data Graphical user interface (GUI) that lets users assemble and implement programs to solve a problem 3/24
What are the advantages and the disadvantages? Advantages interpreted language numerical calculator built in graphics Disadvantages does not work well for large computing projects (many developers) professional GUIs are best written in compiled language 4/24
Programming Language Background Abstraction expressing a quality apart from a particular implementation Algorithm sequence of instructions for solving a sub-program Programming Paradigms a set of assumptions, concepts, values, and practices that constitutes a way of viewing reality for the community that shares them, especially in an intellectual discipline 5/24
What does expressing a quality apart from a particular implementation (abstraction) mean? It is things that we use in everyday conversation He used his bicycle to ride home from campus Procedural abstraction: the details will be different based on the user to instruct the ride home. To convert from lb to N, multiply the force by 4.448 Data abstraction: details about the force will determine how you do the conversion. 6/24
What does sequence of instructions for solving a subprogram (algorithm) mean? Instructions that we use to problem solve Problem: The car needs to be fixed 1) Change the oil 2) Drain the old oil, remove the old oil filter, install a new oil filter, fill the old pan with new oil 3) Place the vehicle on ramps, place a container under the oil pan to catch the old oil, etc. The algorithm is full of abstractions that are based on what is computing the algorithm 7/24
Programming Paradigms You will have a better understanding of programming paradigms after you have learned basic programming 8/24
Now, let s start talking about basic data manipulation within Matlab z = x + y In algebra, this is a two way relationship x + y = z In programming, this is the sum of two values associated to a new name; it can be changed with the next statement z = 4x - y In algebra this represents a constraint on the values, but in programming, this is an assignment statement 9/24
When we start to define data to variables in Matlab, we need to use appropriate syntax Variables upper or lowercase letters, numbers, and _ not $ or 64 unique characters Variables may be words no spaces use underscore or caps velocity_feet_per_second VelocityFeetPerSecond 10/24
Matlab is an untyped language Variables are given a specific type when assigned Issues Numeric (double) x = 7 Character (char) x = I like programming misspelled variables may cause errors (without notice) logic errors with incompatible data Typed languages (weak or strong) allow the programmer to assign types and interactions before running or compilation 11/24
Now, let s look at Matlab and talk about some of the things we see Current Folder Command Window Workspace Tab Command History This layout may be adjusted to the user preference 12/24
One way to adjust the layout is to use the layout feature on the top window 13/24
Matlab can be used in two modes: Command mode or Edit mode Command mode appears as a scientific calculator Edit mode able to type in numerous commands before executing 14/24
Matlab can be used in two modes: Command mode or Edit mode Command mode appears as a scientific calculator Edit mode able to type in numerous commands before executing (use what are called scripts) 15/24
The workspace provides a list of variables always keeps the variables in alphabetical order ans is a special variable The clear command allows you to clear which ever workspace variable you want. Example clear AA BB to clear variable AA and BB or clear all to clear all of the variables (note: the quotes are not used) 16/24
The workspace always keeps the variables in alphabetical order Double clicking on a variable in the workspace will allow you to see the variable and change its value You may also paste the data here from another source 17/24
The Command History pane will allow you to fix mistakes that you have made The clc command allows you to clear all of the stuff that is in the command window, but leaves all of the history and workspace variables to use later whos will allow you to see all of the variable information in the command window 18/24
The output will have specific formats in the Command Window A semicolon will suppress the presentation of the result 19/24
Matlab has built in figure windows that allows you to plot data close, figure 20/24
Matlab has a built in text editor that allows you save a script for running later 21/24
Matlab has a built in text editor that allows you save a script for running later The result will show in the Command Window 22/24
Additional syntax ; close clear clc ^ plot who whos % 23/24
Use the text editor to write your scripts and start using comments Start using the text editor Start using comments Try different commands and see what happens 24/24