Intro MATLAB: Special Purpose Computer Program Optimized to perform engineering and scientific calculations Implements the MATLAB programming language.

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

Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Welcome to EGR 106 Foundations of Engineering II Course information Today’s specific topics: – Computation and algorithms – M ATLAB Basics Demonstrations.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to 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.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
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.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
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,
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
INTRODUCTION TO MATLAB LAB# 01
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Basics of MATLAB By DR. Wafaa Shabana
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful 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.
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.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Matlab for Engineers Matlab Environment Chapter 2.
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.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
Matlab Programming for Engineers
MATLAB Basics Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
2) Platform independent 3) Predefined functions
MATLAB DENC 2533 ECADD LAB 9.
StatLab Matlab Workshop
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Lecture 2 Introduction to MATLAB
Communication and Coding Theory Lab(CS491)
Experiment No. (1) - an introduction to MATLAB
Matlab Basics Tutorial
Presentation transcript:

Intro MATLAB: Special Purpose Computer Program Optimized to perform engineering and scientific calculations Implements the MATLAB programming language – Has an extensive library of predefined functions

Advantages and disadvantages Advantages: – Easy to use Interpreted, not compiled Integrated editor/debugger – Platform Independence Works on Windows, Linux, Unix, and MacIntosh – Many predefined functions E.g., arithmetic mean, standard deviation, median, etc. Disadvantages: – Interpreted, not compiled May execute more slowly

Command Window In command window, can type: – area=pi*2.5^2 If line is too long, can add … to end of line to continue it on the next line E.g., – x1 = 1 + ½ + 1/3 + ¼ + 1/5 + 1/6 – x1 = 1 + ½ + 1/3 + ¼ … + 1/5 + 1/6 Note the space between ¼ and …!

Edit/Debug Window Can create new Matlab files or modify existing ones – Created automatically when you create a new M-file or open an existing one Select File->New->Blank M-file from the desktop menu Select File->Open from the desktop menu – In edit window, type: %This m-file calculates the area of a circle. %and displays the result. radius = 2.5; area = pi * 2.5^2; string = [‘The area of the circle is ‘ num2str(area)]; disp(string); Save file as calc_area.m Run by typing calc_area in Command Window

Figure Windows Used to display MATLAB graphics – Can be a two- or three-dimensional plot of data, an image, or a GUI – Write program to plot sin x: %sin_x.m: This M-file calculates and plots the %function sin(x) for 0 <= x <= 6. x = 0:0.1:6 y = sin(x) plot (x,y) Save as sin_x.m and type sin_x into Command Window

Getting Help in MATLAB 1.Use the Help Browser – ? Icon in desktop toolbar – Type “helpdesk” or “helpwin” in Command Window 2.Type “help” or “help” followed by function name in Command Window – “help” -displays a list of possible help topics – “help” function – displays help for that function 3.“lookfor” command – Searches summaries of each function for a match Helpful in finding a function you don’t know the name of E.g., suppose you wanted to find a function that takes the inverse of a matrix. – There’s no function called “inverse” – Do “lookfor inverse” – Get: » INVHILB Inverse Hilbert Matrix » ACOSInverse cosine » ACOSHInverse Hyperbolic cosine » ACOTInverse Cotangent » ACSCInverse cosecant » ACSCHInverse Hyperbolic secant » ASINInverse sine » ASINHInverse Hyperbolic sine » ATANInverse Tangent » Etc.

Other Useful Commands “demo” in command window (or select demos from the start button – Gives you demos of MATLAB’s capabilities “clc” in command window – Clears content of command window “clf” in command window – Clears content of figure window “clear” in command window – Clears content of workspace Good idea to avoid variables in one program affecting results in another program Abort command (Ctrl-C) – Stops a running program – Good for infinite loops “!” – sends commands to operating system and they are executed as if they’re typed into the operating system’s command prompt – Lets you embed op sys commands into MATLAB programs “diary” filename – Once typed, all input and most output will be echoed into the diary file. Helps find problems – To stop: type “diary off” – To continue: type “diary on”

Matlab vs Python Python Functions: def func(x): “”” Summary of this function goes here Detailed explanation goes here “”” return(x*x) Matlab function [y] = func( x ) %Summary of this function goes here %Detailed explanation goes here y = x*x end

Python vs Matlab def func(): inp = input('would you like to continue?') totalcost = 0 while (inp =='yes'): totalcost = totalcost + 3 inp = input('Would you like to buy something else?') return totalcost Matlab: function [totalcost ]= func() inp = input('would you like to continue?','s'); totalcost = 0; while (strcmpi(inp,'yes') == True) totalcost = totalcost + 3; inp = input('Would you like to buy something else?','s'); end

Python Vs Matlab arr = [3, 2, 8, 1, 4, 7, 9] k = len(arr) print(k) total = 0 for i in range (0,k): total = total + arr[i] print(total); Matlab: arr = [ ] k = length(arr); disp(k) total = 0; for i=1:k %Note where loop starts!!! total = total + arr(i); end disp(total)

Matlab vs Python arr = [3, 2, 8, 1, 4, 7, 9] k = length(arr) print(k) total = 0 for i in range (0,k,2): total = total + arr[i] print(total); Matlab: arr = [ ] k = length(arr); disp(k) total = 0 for i=1:2:k %Note where increment is!!! total = total + arr(i); end disp(total);

Vectors In Matlab A vector is a list of numbers expressed as a 1 dimensional array. A vector can be n×1 or 1×n. –Columns are separated by commas (or spaces): h= [1, 2, 3] –Rows are separated by semicolons: v = [1; 2; 3]

Matrices in Matlab A matrix is a two dimensional array of numbers. For example, this is a 4×3 matrix: m=[3.0, 1.8, 3.6; 4.6, -2.0, 21.3; 0.0, -6.1, 12.8; 2.3, 0.3, -6.1] Columns Rows

Defining (or assigning) arrays An array can be defined by typing in a list of numbers enclosed in square brackets: – Commas or spaces separate numbers. A = [12, 18, -3] or A = [ ] – Semicolons indicate a new row. B = [2, 5, 2; 1, 1, 2; 0, -2, 6]

Array vs. Matrix Operations Example: x = [2,1; 3,4] y = [5,6; 7,8] z = x.* y results in [ 10, 6 21, 32] this is array multiplication z = x * y results in [ 17, 20; 43, 50] this is matrix multiplication So, do NOT forget the dot if you want to do array operations! (.*./.^)

Matrix vs Array Multiplication Multiply a.* b a * b b * c b.* c error b * d –e–error b.* d –e–error a = [ ] b = [ ] c = [ 2 3 ] d = [ 2 3 ]

Left division: q = b\a is equivalent to a x q = b 10x + 5y = 2 2x + 9y = 3 x =.2 -.5y x = y.2 -.5y = 1.5 – 4.5y 4y=1.3 y =.325 x =.2 -.5x.325 x =.0375 So q = [ ; ] (right division: q=a/b is q x a = b, but rarely used!) a = [ ] b = [ 2 3 ]

Example:We know the following: In combining colors: 1.If you combines 7 drops of a red hue, 12 drops of green hue, and 8 drops of the blue hue, you get a saturation of If you combines 3 drops of red, 6 drops of green and 14 drops of blue you get a saturation of 84 3.If you combines 12 drops of red, 2 drops of green, and 4 drops of blue, you get a saturation of 152. First, write this as a system of 3 linear equations: 7x + 12y + 8z = 143 3x + 6y + 14z = 84 12x + 2y + 4z = 152 Next, in matlab, write the matrices representing these equations. A=[7 12 8;b=[143; ; 84; ] 152] Now, in matlab, write the equation that would solve for the 3 variables (red- saturation, green-saturation, and blue-saturation) Sol = b\a Sol: [.0608,.0499,.0579]