Download presentation
Presentation is loading. Please wait.
Published byAlan McDowell Modified over 9 years ago
1
1 CS1371 Introduction to Computing for Engineers Introduction to Matlab
2
2 Learning Objectives Discover how Matlab is designed and what the basic components do. Outline Matlab processor Basic language syntax Numbers in Matlab Matlab Desktop Array Basics Summary
3
3 Matlab Desktop Command Window Launch Pad History
4
4 Matlab Desktop – cont’d Command Window Workspace Current DIrectory
5
5 Matlab Help
6
6 Matlab Programs Matlab is an extravagant calculator if all we can do is execute commands typed into the Command Window… So how can we execute a “program?” Programs in Matlab are: –Scripts, or –Functions Scripts: Matlab statements that are fed from a file into the Command Window and executed immediately Functions: Program modules that are passed data (arguments) and return a result (i.e., sin(x)) These can be created in any text editor (but Matlab supplies a nice built-in editor)
7
7 Matlab Editor Color keyed text with auto indents tabbed sheets for other files being edited Access to commands
8
8 The Matlab Environment Matlab is an interpreted language –Commands are typed into the COMMAND Window and executed immediately –Variables are allocated in memory as soon as they are first used in an expression –Commands must be re-entered to be re-executed All variables created in the Command Window are in what is called the Base Workspace –Variables can be reassigned new values as needed –Variables can be selectively cleared from the workspace The Workspace can be saved to a data file –File extension is.mat (ex: mydata.mat) –File is in binary and essentially unreadable by humans –.mat files can be reloaded back into the Matlab Workspace
9
9 Commands, Statements & Variables At the prompt in the Command Window, you can enter either a: –Command: save mydata (saves workspace in mydata.mat ) whos (displays list of workspace variables) –Assignment Statement: A = width * length; B = 267; Assignment statements can have only a single variable on the left side of the assignment operator (=) The RHS is evaluated using current values for all variables and the resulting value is assigned to the variable on the LHS. Values can be numbers or characters The variable’s TYPE is always updated whenever a new assignment is made (warning: powerful but can lead to mistakes…) –Variables up to 31 characters (more are ignored); Case Sensitive
10
10 Reserved Words… Matlab has some special (reserved) words that you may not use… for end if while function return elsif case otherwise switch continue else try catch global persistent break
11
11 Matlab has Some Special Variables Special VariableDescription ans default variable name for results beep make sound pi mathematical constant eps smallest number that can be subtracted from 0 to make a negative inf infinity NaN not a number i (or) j imaginary number realmin, realmax smallest & largest positive real numbers bitmax largest positive integer nargin, nargout number of function in (or) out variables varargin variable number of function in arg’s varaout variable number of function out arg’s
12
12 Problems to Work 1.You throw a ball straight up in the air with an initial speed of 25 m/s. [g = 9.8 m/s 2 ] a.How long does it take to reach the highest point? b.How high does the ball rise from the release point? c.At what time(s) will it be 25 m above the release point? 2.You are constructing a hemispherical dome with radius 50ft. The walls will be solid concrete 9” thick. How may cubic yards of concrete will be needed? 3.A jet aircraft is flying 100ft above a level plain at 600 mph. Suddenly, the ground begins to rise at a 4 deg slope. How much time does the pilot have to raise the nose before the aircraft strikes the ground?
13
13 Summary Topics Matlab processor Basic language syntax Numbers in Matlab Matlab Desktop Basic Array Manipulation Summary Learning Objectives Discover how Matlab is designed and what the basic components do.
14
14 Questions?
15
15
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.