Date post: | 27-Dec-2015 |
Category: |
Documents |
Upload: | alan-parsons |
View: | 230 times |
Download: | 1 times |
THE MATLAB ENVIRONMENTVARIABLESBASIC COMMANDSHELP
HP 100 – MATLABWednesday, 8/27/2014
www.clarkson.edu/class/honorsmatlab
Who are we?
Jim: Junior Aeronautical – Mechanical Engineer [email protected]
Joe: Senior Mechanical Engineer [email protected]
Quote of the Week
“This is a full time campus. Believe me, there’s nothing exciting going on downtown.”
Prof. Cetinkaya
Before We Begin:
Any Questions? Comments? Concerns? Feel free to contact Jim or Joe
We can set up small group tutoring or one-on-one
You can email us with questions or concerns We are here for you! Even if it isn't about
MATLAB
Homework
Create and submit a PDF file using the publish tool in Matlab
Feel free to work in groups! Do NOT have identical code Questionable integrity will be examined This is your FIRST & FINAL WARNING
The Editor
The Editor is a supped up ‘notepad’ It is where you will be spending most of your time. It allows you to write your code, save it, open it up again,
run it as well as many more advance options. Open it from:
New Script The “New” icon has options to create other different
things like functions and GUIs
The Editor [cont.]
Line Number
Save & Run script
Where MATLAB will try to point out possible errors with your code, and offer suggestions! How nice!
MATLAB FUNDAMENTALS
• The 'Supped-Up Graphing Calculator'– In the command window:
25 + 5 <<enter>>
• Result:ans = 30 <<line spaces removed>>
– So… what does this mean?• You can use the command window like a
scratch-pad or calculator, using familiar math symbols.Addition: a + b Multiplication: a * b
Subtraction: a - b Division: a / b
Exponentiation: a^b
MATLAB FUNDAMENTALS
Order of Operations Parentheses left to right Exponents left to right Division AND Multiplication left to right Addition AND Subtraction left to right
MATLAB FUNDAMENTALS
Creating Variables / Arrays The assignment operator =
<<variable_name>> = <<data to be stored>>; Variable names must begin with a letter
and can only contain letters, numbers, and the underscore.
Examples: x = 1; y = [1 2 3 4]; z = [1 0 0; 0 1 0; 0 0 1];
MATLAB FUNDAMENTALS
Variables and Arrays Variables store values (numbers and text) Scalar
Vector
Array (Matrix)
MATLAB FUNDAMENTALS
Mathematical Operations with arrays Use .* ./ .^ when using operation on an array or
vector Array Indexing
Indexing an array is to specify a specific location to extract its value and or to perform an operation.
Arrays are indexed as follows: A(i,j) Refers to the ith row
and jth column.
9 8 7
6 5 4
3 2 1
i
j
Elementary MATLAB CommandsFunction Syntax (What to type in) Example
Display disp(‘Hello’)
disp(x)
Hello
5
Trig Functions sin(pi/2) 1
Square Root sqrt(16) 4
Remainder rem(15,6) 3
Size d=[1 2 3;4 5 6]
size(d)
[2 3]
Clear clear (Clears all variables)
Clear Screen clc (Clears Screen)
Numerical Display
See page 39 in your texts
MATLAB Command Display Example
format short 4 decimal points 3.1416
format long 14 decimal points 3.14159265358979
format short e 4 decimal points 3.1416e+000
format long e 14 decimal digits 3.141591643589793e+000
format bank 2 decimal digits 3.14
format + +, -, blank +
format rat Fractional form 355/113
Help command
Help function: Universal! Solves many problems created by Jim and
Joe!! ‘help’ is a great place to start when
totally lost ‘help _______’ insert a function in the blank
ie cos, solve, plot, etc… Mathworks website has an explanation
for every function in matlab
Publishing
Go to the Publish tab Click the drop box below the Publish icon
and select edit publishing options Change the output format to PDF
Click the Publish icon
Questions?
Questions? HW # 1
Due by 5:00 PM, Wednesday September 3rd, to [email protected]
You are to submit: PDF file of your published code Make sure to use comments % Question 2.2 Problems: 2.2, 2.3, 2.4