Matlab
Last Modified 11/20/08
Overview
•
Comparing to C++
•
Examples, Set 1
•
Methods
•
Control Structures
•
Plotting
•
Examples, Set 2
What is it?
Matlab, short for
Mat
rix
Lab
oratory, is a computational environment especially for working with matrices.
In fact, by default, everything in Matlab is a matrix. But is also does computations with scalar values and is
good at plotting as well.
Matlab has its own language and environment to interpret the language. The language is not compiled; each
line of code is handled by the environment, one line at a time.
We'll spend this lecture and the remaining lab periods working with the basics of this software and its
language. You'll find that now that you know C++, learning the language of Matlab won't be nearly as
difficult. You are not expected to become an expert in this time, but rather to know what Matlab can do for
you and know how to do basic things in Matlab so that when you need to use it in another course, it's not
foreign to you.
Overview
•
Comparing to C++
•
Examples, Set 1
•
Methods
•
Control Structures
•
Plotting
•
Examples, Set 2
Comparing and Contrasting to C++
I'll begin by discussing how Matlab compares to C++:
•
No advance declarations, but almost the same naming rules for variables.
•
When first using a variable, document it as you would have in C++ at declaration.
•
Watch case sensitivity and spelling very carefully.
myVariable
and
myvariable
are two
different variables, but Matlab won't give you that nice "undeclared identifier" error.
•
Two places to write code:
•
A console window where you can enter commands and see output.
•
A .m file where you write code in advance. Output from here goes to the console window.
•
Not the same idea of user interaction:
•
No prompttheninput. Instead initialize variables to the values you want in the code.
•
Output is a matter of displaying numeric results to the console. Use the documentation for
labels.
•
(Technically, there is an ability to do the kind of I/O we know, but we're just going to use
Matlab in command line mode.)
•
Semicolon at end of statements is optional:
•
With no semicolon, the output of the statement is displayed to the console.
•
Use a semicolon to suppress the output.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document•
Specially designed for matrices, so there are additional operators for matrices. For example,
*
multiplies matrices, but
.*
multiplies the individual elements of matrices.
•
Comments begin with
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '10
 matlab, Dot Product, Control Structures

Click to edit the document details