Intro to Matlab 1.Using scalar variables 2.Vectors, matrices, and arithmetic 3.Plotting 4.Solving Systems of Equations Can be found at:http://www.cs.unc.edu/~kim/matlab.ppt.

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Lecture 5.
Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Intro to Matlab 1.Vectors, matrices, and arithmetic 2.Plotting 3.Flow Constructs 4.Other Useful Things Can be found at:
Linear Simultaneous Equations
Matrix Mathematics in MATLAB and Excel
1 Chapter 3 Matrix Algebra with MATLAB Basic matrix definitions and operations were covered in Chapter 2. We will now consider how these operations are.
1 Chapter 2 Matrices Matrices provide an orderly way of arranging values or functions to enhance the analysis of systems in a systematic manner. Their.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Chapter 10 Review: Matrix Algebra
Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 8 Linear Algebraic Equations PowerPoint to accompany Copyright © 2010.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Mathematics of Cryptography Modular Arithmetic, Congruence,
Matlab tutorial course Lesson 2: Arrays and data types
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
1 Statistical Computing in MATLAB AMS 597 Ling Leng.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Introduction to MATLAB
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
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.
4.4 & 4.5 Notes Remember: Identity Matrices: If the product of two matrices equal the identity matrix then they are inverses.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
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.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
CMPS 1371 Introduction to Computing for Engineers MATRICES.
Lecture 28: Mathematical Insight and Engineering.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
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.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Introduction to MATLAB Session 1 Simopekka Vänskä, THL 2010.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
OUTLINE Overview Numbers, variables and similar in Matlab
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
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.
Lecture 1: Matlab Universe
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Matlab Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
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 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
“Moh’d Sami” AshhabSummer 2008University of Jordan MATLAB By (Mohammed Sami) Ashhab University of Jordan Summer 2008.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 8 Linear Algebraic Equations and Matrices.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
Chapter 7 Matrix Mathematics
Introduction to Matlab
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Use of Mathematics using Technology (Maltlab)
Vectors, matrices, and arithmetic
Experiment No. (1) - an introduction to MATLAB
Presentation transcript:

Intro to Matlab 1.Using scalar variables 2.Vectors, matrices, and arithmetic 3.Plotting 4.Solving Systems of Equations Can be found at:

New Class--for Engineers ENGR196.3 SPECIAL TOPICS: INTRODUCTION TO MATLAB Description: Fundamentals of MATLAB programming applied to problems in science and mathematics. Solving systems of equations, basic scripting, functions, vectors, data files, and graphics. (Credit course for grade or CR/NC)

Why use Matlab? Drawbacks: Slow (execution) compared to C or Java Advantages: Handles vector and matrices very nice Quick plotting and analysis EXTENSIVE documentation (type ‘help’) Lots of nice functions: FFT, fuzzy logic, neural nets, numerical integration, OpenGL (!?) One of the major tools accelerating tech change

A tour of Matlab’s features Click on Help>Full Product Family Help: Check out Fuzzy Logic Genetic Algorithms Symbolic Math

Scalars The First Time You Bring Up MATLAB MATLAB as a Calculator for Scalars Fetching and Setting Scalar Variables MATLAB Built-in Functions, Operators, and Expressions Problem Sets for Scalars

3-1 The First Time You Bring Up MATLAB Basic windows in MATLAB are: Command - executes single-line commands Workspace - keeps track of all defined variables Command History - keeps a running record of all single line programs you have executed Current Folder - lists all files that are directly available for MATLAB use Array Editor - allows direct editing of MATLAB arrays Preferences - for setting preferences for the display of results, fonts used, and many other aspects of how MATLAB looks to you

3-2 MATLAB as a Calculator for Scalars A scalar is simply a number… In science the term scalar is used as opposed to a vector, i.e. a magnitude having no direction. In MATLAB, scalar is used as opposed to arrays, i.e. a single number. Since we have not covered arrays (tables of numbers) yet, we will be dealing with scalars in MATLAB.

3-3 Fetching and Setting Scalar Variables Think of computer variables as named containers. We can perform 2 types of operations on variables: we can set the value held in the container: x = 22 we can set the value held in the container: x = 22 we can look at the value held in the container: x

The Assignment Operator (=) The equal sign is the assignment operator in MATLAB. >> x = 22 places number 22 in container x How about: >> x = x + 1 Note the difference between the equal sign in mathematics and the assignment operator in MATLAB!

Useful Constants Inf infinity NaN Not a number (div by zero) epsmachine epsilon ansmost recent unassigned answer pi …. i and jMatlab supports imaginary numbers!

Using the Command History Window

3-4 MATLAB Built-in Functions, Operators, and Expressions MATLAB comes with a large number of built-in functions (e.g.. sin, cos, tan, log10, log, exp) A special subclass of often-used MATLAB functions is called operators –Assignment operator (=) –Arithmetic operators (+, -, *, /, ^) –Relational operators ( =, >) –Logical operators (&, |, ~)

Example – Arithmetic Operators Hint: the function exp(x) gives e raised to a power x

Example – Relational and Logical Operators

Vector Operations Chapter 5

Vector Operations Vector Creation Accessing Vector Elements Row Vectors and Column Vectors, and the Transpose Operator Vector Built-in Functions, Operators, and Expressions

Vectors and Matrices Can be to command line or from *.m file scalar:x = 3 vector: x = [1 0 0] 2D matrix:x = [1 0 0; 0 1 0; 0 0 1] arbitrarily higher dimensions (don’t use much) Can also use matrices / vectors as elements: x = [1 2 3] y = [ x 4 5 6]

2-D Plotting and Help in MATLAB Chapter 6

2-D Plotting and Help in MATLAB Using Vectors to Plot Numerical Data Other 2-D plot types in MATLAB Problem Sets for 2-D Plotting

6-2 Using Vectors to Plot Numerical Data Mostly from observed data - your goal is to understand the relationship between the variables of a system. Determine the independent and dependent variables and plot: speed = 20:10:70; stopDis = [46,75,128,201,292,385]; plot(speed, stopDis, '-ro') % note the ‘-ro’ switch Don’t forget to properly label your graphs: title('Stopping Distance versus Vehicle Speed', 'FontSize', 14) xlabel('vehicle speed (mi/hr)', 'FontSize', 12) ylabel('stopping distance (ft)', 'FontSize', 12) grid on Speed (mi/hr) Stopping Distance (ft)

Sample Problem – Plotting Numerical Data

3D Plotting 3D plots – plot an outer product x = 1:10 y = 1:10 z = x’ * y mesh(x,y,z) Single quote ‘ means transpose (can’t cut and paste though…)

Flow Constructs IF block if ( ) elseif end WHILE block while ( ) end Conditions same as C, ( ==, >=, <=) except != is ~=

More Flow Constructs FOR block for i = 1:10 end SWITCH statement switch case, otherwise, end

Other Language Features Matlab language is pretty sophisticated –Functions Stored in a *.m file of the same name: function = ( ) –Structs point.x = 2;point.y = 3;point.z = 4; –Even has try and catch (never used them)

Solving Systems of Equations Consider a system of simultaneous equations 3x + 4y + 5z = 32 21x + 5y + 2z = 20 x – 2y + 10z = 120 A solution is a value of x, y, and z that satisfies all 3 equations In general, these 3 equations could have 1 solution, many solutions, or NO solutions

Using Matlab to Solve Simultaneous Equations Set up the equation in matrix/vector form: A = [3 4 5; ; ] u = [ x y z]’ b = [ ]’ In other words, A u = b (this is linear algebra) x y z * =

The solution uses matrix inverse If you multiply both sides by 1/A you get u = 1/A * b In the case of matrices, order of operation is critical (WRONG: u = b/A ) SO we have “Left division” u = A \ b (recommended approach) OR use inv( ) function: u = inv(A) * b

The solution >> u = A\b u = ( value of x) ( value of y) ( value of z) You can plug these values in the original equation test = A * u and see if you get b

Caution with Systems of Eqs Sometimes, Matrix A does not have an inverse: This means the 3 equations are not really independent and there is no single solution (there may be an infinite # of solns) Take determinant det(A) if 0, it’s singular x y z * =