MATLAB FUNDAMENTALS: MATRIX/ARRAY FUNCTIONS THE COLON MATRIX/ARRAY MANIPULATION INPUT/OUTPUT HP 100 – MATLAB Wednesday, 9/3/2014 www.clarkson.edu/class/honorsmatlab.

Slides:



Advertisements
Similar presentations
COMP 116: Introduction to Scientific Programming Lecture 37: Final Review.
Advertisements

Functions in MatLab Create a new folder on your Z:drive called MatLab_Class24 Start MatLab and change your current directory to MatLab_Class24 Topics:
Program Design. Objectives Students should understand the basic steps in the programming process. Students should understand the need for good design.
CS231A Matlab Tutorial Philip Lee Winter Overview  Goals › Introduction to Matlab › Matlab Snippets › Basic image manipulations › Helpful Matlab.
Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming with MATLAB
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Concatenation MATLAB lets you construct a new vector by concatenating other vectors: – A = [B C D... X Y Z] where the individual items in the brackets.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Fibonacci Problem Solving and Thinking in Engineering Programming H. James de St. Germain.
MATLAB FUNDAMENTALS: INPUT/OUTPUT LOGIC CONTROL STRUCTURES HP 101 – MATLAB Wednesday, 9/24/2014
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files called M- files. M-files are.
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Introduction to MATLAB
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Fall 2006AE6382 Design Computing1 Control Statements in Matlab Topics IF statement and Logical Operators Switch-Case Disp() vs fprintf() Input() Statement.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
File I/O High-Level Functions 1. Definition 2. Is a High-Level function appropriate? 3. xlsread() 4. dlmread() 1.
Hey, Ferb, I know what we’re gonna do today! Aims: Use formatted printing. Use the “while” loop. Understand functions. Objectives: All: Understand and.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Scientific Computing Introduction to Matlab Programming.
1 Input / Output Input – reads/gets data for the program Output – the product, after processing Both can be: interactive I/O (while program is running)
September 13, 2005 Lecture 4 - By P. Lin 1 CPET 190 Lecture 4 Problem Solving with MATLAB
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
ENG College of Engineering Engineering Education Innovation Center 1 More Script Files in MATLAB Script File I/O : Chapter 4 1.Global Variables.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 2: Sub-Arrays Friday 05 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Matlab Data types, input and output. Data types Char: >> a = ‘ Jim ’ Char: >> a = ‘ Jim ’ Numeric: uint8, uint16, uint32, uint64 int8, int16, int32, int64.
Fall 2006AE6382 Design Computing1 Control Statements in Matlab Topics IF statement and Logical Operators Switch-Case Disp() vs fprintf() Input() Statement.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
INTRODUCTION TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in.
MATLAB – More Script Files
EEE 161 Applied Electromagnetics
Introduction to Matlab
EGR 115 Introduction to Computing for Engineers
Control Statements in Matlab
Lecture: MATLAB Chapter 1 Introduction
Python I/O.
Matlab review Matlab is a numerical analysis system
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Basic Lessons 5 & 6 Mr. Kalmes.
Programming The ideal style of programming is Structured or
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Presentation transcript:

MATLAB FUNDAMENTALS: MATRIX/ARRAY FUNCTIONS THE COLON MATRIX/ARRAY MANIPULATION INPUT/OUTPUT HP 100 – MATLAB Wednesday, 9/3/2014

Before We Begin:  Any Questions? Comments? Concerns?  Feel free to contact Joe or Jim We can set up small group tutoring or one-on-one You can us with any questions or concerns We are here for you! Even if it isn't about MATLAB

Quote/Video of the Week  “English is ambiguous. If someone said, ‘The horse flies like the devil,’ they could either be advising me on a horse race, or merely commenting on the rising tide of Satanism among some insects.” - Professor Felland Foundations of Mathematics

Matrix/Array Functions  A = [1 1 1; 1 1 1]  B = [0 0; 0 0; 0 0]  C = [1 1; 1 1] A = B = C =

Matrix/Array Functions  A = ones(2,3)  B = zeros(3,2)  C = ones(2) A = B = C =

Matrix/Array Functions  Built in Commands/Functions: See Tables 3.5,6,7  max: Maximum Value  min: Minimum Value  mean: Mean Value  median: Median Value  sum: Sum of Vector  prod: Product of Vector

Matrix/Array Functions  Sorting FunctionsTable 3.8  sort  sortrows  Size FunctionsTable 3.9  size Dimensions of Array  length Largest Dimension

Special Values / Misc.  The following have special meanings:  pi - The constant …  i,j - Imaginary Number  Inf - Infinty, or overflow  NaN - Not a number, Undefined (0/0)  clock - [year month day hour minute seconds]  date

The Colon Operator  Used for:  Creating Vectors  Referencing arrays  Future applications [loops]

Creating Vectors  A = [ ]  B = [2:2:12]  C = [4:6:30] A = B = C =

The Colon Operator  Let:  A(2,3) =  A(1, :) =  A(:, 3) =  A(:, 1:2:4) = A =

The Colon Operator  Built-in function – end  A(:,end)= [13; 6; 8]  A(end,end) = 8  diag(A) = [4; 2; 8] A =

Matrix/Array Manipulation  You can define new arrays or matrices in terms of other arrays or matrices.  This can be tricky, but always try to say it out loud and visualize what is happening.

I/O – Input / Output  Definition:  Hardcoding:Setting variables equal to particular numbers in the code. Example: Calculate the square root of a number. number = 100; sqrt_of_number = sqrt(number); The code snippet always calculates the square root of 100, unless you manually change the code. What if we want to do it for the number the user chooses (whomever is using your program/code)?

I/O – Input / Output  Methods:  Ask the user for input through the command window.  Load data from files.  Function inputs (We will get to this in a few weeks.)  Input Command:  number = input('Please Specify a Number: ');

I/O – Input / Output  Loading data from files:  Many different ways, depending on what type of file it is. We do this in the future. Use the load command.

I/O – Input / Output  Calculations, Manipulation, Calculations…  We Still need to display our Results  Methods:  Display in the command window Good for quick solutions, small amount of data. Commands: dispfprintf  Write the results to a file. Great for processing and saving lots of information. A bit harder to do, can be highly customized. Commands: fprintfsave

I/O – Input / Output  Command: disp  Example: x = 5; disp(x); disp(['The value of x is ' num2str(x) ‘. Cool Ehh?’]); Tells MATLAB to combine everything inside together into an array, in this case, a character array Things inside of single quotation marks are strings, or just simply text (stored as plain text) Converts a number to a string.

I/O – Input / Output  Command: fprintf  This can be used to either print out to the command window or write to a file.  This is saved for your own reading/learning.  It’s another way to display, also. It allows for more formatting and pretty outputs

Example Code Time  The Golf Ball Example  Please take note of lots of little things that are done, they add to the readability and to the end results being pretty  Problem Description: Calculate the X-Position and Y-Position of a golf ball hit with an initial speed and angle. Assume constant acceleration from gravity and no drag. Also find the maximum height and display the results.

Homework  Please review/read:  Chapter 3, Chapter 4  It is very important to review the tables indicated and go through the example problems.  Please do:  3.4, 4.1, 4.6

Before you go…  Do Problem 4.1 in the book