Introduction to Matlab

Slides:



Advertisements
Similar presentations
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Advertisements

Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
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.
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.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Computer Science 111 Fundamentals of Programming I Basic Program Elements.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
INTRODUCTION TO MATLAB LAB# 01
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Introduction to Programming with RAPTOR
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Ch13-1 Chap 13 Introduction to Matlab 13.1 Introduction MATLAB : The MATrix LABoratory program Not only is the MATLAB programming language exceptionally.
1 CS1371 Introduction to Computing for Engineers Control Statements 9/4/2003.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.
Matlab Workshop Getting Started.
מטלב וניתוח נתונים ממערכות עצביות היכרות עם MATLAB
ECE 1304 Introduction to Electrical and Computer Engineering
Topics Designing a Program Input, Processing, and Output
Built-in MATLAB Functions Chapter 3
L2. Basics Variables and Expressions Assignment Statements
L – Modeling and Simulating Social Systems with MATLAB
Lecture: MATLAB Chapter 1 Introduction
Introduction to MATLAB for Engineers, Third Edition
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Matlab review Matlab is a numerical analysis system
Introduction to C++ Programming
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
Introduction to MATLAB
Communication and Coding Theory Lab(CS491)
Introduction to MATLAB
INTRODUCTION TO MATLAB
Introduction to MATLAB
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.
Topics Designing a Program Input, Processing, and Output
Simulation And Modelling
Experiment No. (1) - an introduction to MATLAB
Topics Designing a Program Input, Processing, and Output
Using Script Files and Managing Data
Announcements P3 due today
Terminal-Based Programs
CS 111 Introduction to Computing in Engineering and Science
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Matlab Basics Tutorial
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
Introduction to Matlab
Programming The ideal style of programming is Structured or
Presentation transcript:

Introduction to Matlab CS100A, Fall 1998 Lecture 18, Tuesday Nov 3 Introduction to Matlab Concepts: Matlab as a graphical calculator for scalars & arrays Readings: choose one of: Getting Started with Matlab, Pratap Mastering Matlab, Hanselman & Littlefield Student Edition of Matlab User’s Guide, Hanselman & Littlefield or any other basic Matlab book

Why Matlab? The premier package for numerical computing, particularly arrays (matrices). Widely used in science/engineering. Provides high-level interface to best-of-class numerical methods. Problem-solving without lower-level programming details. Powerful graphics and visualization tools. has variables, loops, conditionals, functions but much array/matrix computation can be done directly without loops.

Matlab Environment Enter expressions or commands in the console window. Commands are executed immediately. An expression is evaluated and its value is immediately displayed. Can define command scripts and new functions (future lecture). Most important feature: help command. Enter help to get a general list of available topics, or help topic for information on topic. Enter more on in the console window to pause output after each full screen. Hit space to continue. Anything following a % is ignored. Use it to include notes or comments in a session. To leave Matlab, enter quit

^ is exponentiation (2 ^ 10) Expressions The usual basic arithmetic operations are provided (+, –, *, /, and ^). Everything is floating-point†, although integer values are displayed without a fractional part. 9/10 is 0.9 in Matlab ^ is exponentiation (2 ^ 10) Logical operations treat 1 as the value true and 0 as false. Comparisons: <, <=, ==, ~=, >=, > Logical Operators: &, |, ~ Examples: 3 * 4 + 5 3 * 4 + 5 / 2 3 * (4 + 5) / 2 (3 < 2 ^ 2) & ~ (3 < 2) (3 < 2 ^ 2) | ~ (3 < 2) † Actually, everything in Matlab is a matrix containing complex, floating-point numbers. But for now we can restrict ourselves to integers and real numbers.

Variables Variables are created when they are first assigned a value. x = 17 y = 3 * x All variables are global (for now). A variable exists from the time it is created until you quit Matlab. Variable names are case-sensitive. Entering a = 17 A = 42 creates two separate variables. Several variables containing useful constants are already defined pi 3.14159… Inf i, j sqrt(–1) NaN 0/0

Syntax: function-name ( arg1, arg2, … ) Examples: x = 3; y = 4; Functions Matlab provides a rich collections of standard functions. Trigonometry: sin, cos, tan, cot, asin, acos, atan, atan2… Exponential: exp, log, log10, sqrt Complex: real, imag, abs, … Rounding: floor, ceil, round, rem, sign Specialized: bessel, gamma, erf, log2, rat, … Syntax: function-name ( arg1, arg2, … ) Examples: x = 3; y = 4; d = sqrt(x ^ 2 + y ^ 2) sin(pi / 2) exp(1) sqrt(–1)

Output and Input The value of a Matlab expression or statement is displayed immediately unless it is followed by a semicolon. z = x ^ 2 w = x ^ 3; To change the precision of the output enter format long format short Other formats are also available. (Enter help format for details.) You can edit and reenter previous console input. Use the up- and down-arrow keys to access previous entries.

A single value, called a scalar, is simply an array of size 1. Arrays (Vectors) All data in Matlab is actually an array — a 1- or 2-dimensional table of numbers. (We only consider 1-D arrays in this lecture.) A single value, called a scalar, is simply an array of size 1. To construct a 1-D array, list its elements surrounded by square brackets. y = [4 -5 10 0 5.2] x = [–5 sqrt(2) 17 2^3] Individual elements are accessed using a parenthesized subscript. x(3) The first element of array x is x(1). Can assign to elements of array as in Java. y(1) = 0 The number of elements in array x is given by the built-in function length(x)

Array Functions An array of evenly-spaced values can be generated by linspace(minVal, maxVal, nVals) Example: array of 100 values spaced from 0 to 2. v = linspace(0, 2*pi, 100); There are many functions to compute facts about arrays. min(x) max(x) mean(x) sum(x) x(1) + … +x(length(x)) prod(x) x(1) * … * x(length(x)) cumsum(x) cumulative sum

Creating Arrays Two arrays can be combined with a comma and brackets: x = [1 2 3]; y = [4 5 6]; [x, y] (is [1 2 3 4 5 6]) z = [x, [x, y]];

Creating Arrays The colon can be used to generate a sequence of values. Forms: lowValue : highValue lowValue : step : highValue Examples: 1 : 10 1 : 2 : 10 1 : 0.5 : 10 10 : –1 : 1 0 : 0.01 : 0.5 A sequence of values is an array value. a = 0 : 2 : 16 b = [1 : 6] / 3 A sequence of integers can also be used to select a segment of an array. a(3:6)