Cracking the Code: Using Quantitative Models in MATLAB to Solve Problems
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the...
-
Upload
gwendolyn-reeves -
Category
Documents
-
view
214 -
download
0
Transcript of Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the...
![Page 1: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/1.jpg)
Objectives
Understand what MATLAB is and why it is widely used in engineering and science
Start the MATLAB program and solve simple problems in the command window
![Page 2: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/2.jpg)
What is MATLAB?MATLAB is one of a number of commercially available, sophisticated mathematical computation toolsOthers include
MapleMathematicaMathCad
![Page 3: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/3.jpg)
MATLAB is both a powerful computational environment and a programming language that easily handles matrix and complex arithmetic.
It is a large software package that has many advanced features built in, and it has become a standard tool for many working in science or engineering disciplines.
Among other things, it allows easy plotting in both two and three dimensions.
What Is MATLAB?
![Page 4: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/4.jpg)
MATLAB is good at:
• Numerical calculations– Especially:matrices
• Graphics• MATLAB stands for
Matrix Laboratory
![Page 5: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/5.jpg)
Why MATLAB• Easy to use• Built in programming language
MATLAB was originally written in Fortran, then later rewritten in C
![Page 6: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/6.jpg)
Release Numbers
• MATLAB is updated regularly• The Mathworks packages their software in
groups, called releases, New releases are issued twice a year in the spring and in the fallRelease 2013a includes– MATLAB 8.1– A number of specialized “toolboxes”
![Page 7: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/7.jpg)
MATLAB in Industry• Widespread, Tool of choice in Academia for most engineering
and science fields• MATLAB is also being used in the medical field. These images
were created from MRI data, using MATLAB.
![Page 8: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/8.jpg)
MATLAB has two different methods for executing commands: interactive mode and batch mode.
In interactive mode, commands are typed (or cut and pasted) into the command window.
In batch mode, a series of commands is saved in a text file with a .m extension. The batch commands in a file are then executed by typing the name of the file at the MATLAB command prompt.
What Is MATLAB?
![Page 9: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/9.jpg)
MATLAB is an interpreted language. Commands are executed line by line.
It supports two basic types: characters like 'a' (16 bits) and doubles like 8.25 (64 bits).
Most of the time MATLAB works with arrays or matrices of real numbers or characters.
Other types are also supported: complex, symbolic (if installed), 16-bit and 8-bit integers, etc...
The MATLAB Language
![Page 10: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/10.jpg)
Problem Solving• A standardized approach to problem solving commonly
found in all science disciplines.• 1.first you state the problem, • 2.then describe the input and output.• 3. Develop a plan for solving the problem, called an
algorithm. • 4.Then you actually solve the problem, in our case using
MATLAB, and • 5. finally you test your solution for reasonableness.
If you use a consistent problem solving strategy you increase the chance that your result is correct
![Page 11: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/11.jpg)
MATLAB
![Page 12: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/12.jpg)
• MATLAB uses a standard windows menu bar
• To exit MATLAB use the close icon
![Page 13: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/13.jpg)
Command Window
Enter commands at the prompt
MATLAB WindowsCommand History Window Records all commands issued in the command window – including mistakes
Current Folder WindowLists files stored in the current directory
Workspace Window
![Page 14: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/14.jpg)
The MATLAB DesktopCu
rren
t Fol
der W
indo
w
Command Window
Workspace Window
Command History Window
![Page 15: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/15.jpg)
Let’s look at the windows one at a time
![Page 16: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/16.jpg)
At the prompt (>>), type in a MATLAB command. Press the ENTER key.
MATLAB displays the result in the command window, followed by a prompt.
Repeat the process.
The Command Window
![Page 17: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/17.jpg)
To start a command, make sure cursor is next to the prompt.
MATLAB won’t respond until you press ENTER. It then executes only the last command.
Commands before the last one may still be visible, but MATLAB doesn’t execute them.
Notes on the Command Window
![Page 18: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/18.jpg)
You can type several commands in the same line by putting a comma between commands. (makes the program harder to read though, so it is not recommended).
If a command is too long to fit on one line, you can continue to the next line by typing ellipsis (3 periods, i.e., … ) and then pressing ENTER.
Notes on the Command Window
![Page 19: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/19.jpg)
When cursor is in the bottom (current) command line:
key moves the cursor one character to the left.
key moves the cursor one character to the right.
key recalls the preceding command
key recalls a previous command if it follows.
Navigating the Command Window
![Page 20: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/20.jpg)
Command Window
• Similar to a scratch pad• Once you hit enter, you can’t edit any
commands• You can retype them or use the arrow keys
to retrieve commands and edit them before hitting enter again
Command Window
![Page 21: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/21.jpg)
The PAGE-UP key moves up to previous commands in a window-size at a time.
The PAGE-DOWN key moves down to previous commands in a window-size at a time.
The BACKSPACE (Delete on Mac) key deletes one character to the left of the cursor.
The DELETE (fn-Delete on Mac) key deletes one character to the right of the cursor.
Navigating the Command Window
![Page 22: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/22.jpg)
To quickly execute a previous command but with small changes:
Recall the command with the up and down arrow keys.
Use the left and right arrow keys to move to characters to be altered.
Use BACKSPACE (Mac: Delete) or DELETE (Mac: fn-Delete) to remove old characters, then type new characters.
Press ENTER to execute the modified command.
T I P
![Page 23: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/23.jpg)
Semicolon (;)
When typed at end of a command, it suppresses the output. (only the prompt is displayed at the next line)
Useful for preventing display of large outputs
Used much more in scripts (see Section 1.8 of text book)
Percent sign (%)
When typed at beginning of a line, MATLAB treats the line as a comment and doesn’t execute the line.
Also used much more in scripts.
Command Syntax
![Page 24: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/24.jpg)
Clears the command window display.
The up and down arrows still bring back the previous commands.
The clc Command
![Page 25: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/25.jpg)
Shows the previous commands, including the ones from previous MATLAB sessions.
Double-clicking on a command puts it in the command window and executes it.
You can drag a command to the command window, make changes in it, then execute it.
The Command History Window
![Page 26: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/26.jpg)
Command History
• Records the commands you issue in the command window
• When you exit the command window, or when you issue the clc command, the command window is cleared
• But the command history remains
Command History
![Page 27: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/27.jpg)
Command History
• You can transfer commands from the command history to the command window– Double click on a command• It executes immediately
– Click and drag into the command window• You can edit the command before executing
![Page 28: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/28.jpg)
Workspace Window
Workspace Window
![Page 29: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/29.jpg)
NOTE!• When you define variables in the command window, they are
listed in the workspace window• Document Window:If you double click on any variable in the workspace window
MATLAB launches a document window containing the array editor
You can edit variables in the array editor• Figure Window:When Figures are created a new window opensIt’s extremely easy to create graphs in MATLAB
![Page 30: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/30.jpg)
The Figure Window
The Figure Window opens automatically after any command that draws a graph.
Figure Window
![Page 31: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/31.jpg)
Scalar
Vector
2-D Matrix
![Page 32: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/32.jpg)
Current Directory/Folder
• The current folder window is a list of files• When you try to load information from a file
or try to save information – MATLAB uses the current folder
![Page 33: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/33.jpg)
The Document Window displays the variable editor
New Variable Icon
![Page 34: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/34.jpg)
Note: The semicolon suppresses the output from each command
First create a vector of x values – then a corresponding vector of y values
![Page 35: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/35.jpg)
Matlab makes it easy to modify graphs by adding
•Titles
•Axis labels
•Legends
•Other types of annotations
![Page 36: Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.](https://reader035.fdocuments.in/reader035/viewer/2022062804/56649e715503460f94b703c9/html5/thumbnails/36.jpg)