MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.

Slides:



Advertisements
Similar presentations
Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Advertisements

Introduction to Matlab
Matlab Programming Huajun Wang Department of Earth Sciences, Zhejiang University Jan 25,2012.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Programming with MATLAB
ECEN/MAE 3723 – Systems I MATLAB Lecture 1. Lecture Overview  Introduction and History  Matlab architecture  Operation basics  Visualization  Programming.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
MATLAB and Simulinklecture 31 To days Outline  Functions  Strings  Sparse Arrays  Cell Arrays  Structures  Exercises on this days topics.
C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING 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.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
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.
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,
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
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.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
ENGR 1320 Final Review - Programming Major Topics: – Functions and Scripts – Vector and Matrix Operations in Matlab Dot product Cross product – Plotting.
Eng Ship Structures 1 Introduction to Matlab.
INTRODUCTION TO MATLAB LAB# 01
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
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.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
September 13, 2005 Lecture 4 - By P. Lin 1 CPET 190 Lecture 4 Problem Solving with MATLAB
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
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.
Digital Image Processing Introduction to M-function Programming.
Introduction to Matlab
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 Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
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.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
ECE 1304 Introduction to Electrical and Computer Engineering
Matlab Training Session 4: Control, Flow and Functions
2) Platform independent 3) Predefined functions
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Matlab review Matlab is a numerical analysis system
Use of Mathematics using Technology (Maltlab)
Lecture 2 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.
Experiment No. (1) - an introduction to MATLAB
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
Computer Simulation Lab
Presentation transcript:

MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando file  Exercises on this days topics

MATLAB and SimulinkLecture 12 Introduction Course schedule W35-W41 Tuesdays S319 Theory Tuesdays L337/338Free Exercises Thursdays10-12L337/338Exercises Thursdays L337/338 Laboratory work W (44)Project Work

MATLAB and SimulinkLecture 13 Introduction No written examination Grades U – G Laboratory Works Solutions posted by mail, comment the code! Minor Project You should come up with an idea for the project Use your knowledge of MATLAB and Simulink in the project. Presentation of the project.

MATLAB and SimulinkLecture 14 Introduction Litterature Stephen J Chapman(2005). MATLAB Programming for Engineers ISBN: Dabney J.B and Harman T.L (2004). Mastering Simulink ISBN: Additional reading, see course information

MATLAB and SimulinkLecture 15 Introduction MATLAB is used for calculation and visualizing is programmable contains various commands and functions can interact with other program languages as: C, FORTRAN, JAVA etc. uses arrays as the basic data type

MATLAB and SimulinkLecture 16 MATLAB Desktop Command Window Present results Enter commands Editor/Debug Window Create M-files Debug M-files

MATLAB and SimulinkLecture 17 MATLAB Desktop Command History View previous commands

MATLAB and SimulinkLecture 18 MATLAB Desktop Current Directory File Manipulation Files in current directory

MATLAB and SimulinkLecture 19 MATLAB Desktop Workspace Shows variables defined in workspace

MATLAB and SimulinkLecture 110 MATLAB Desktop Help Demos Tutorials Documentations

MATLAB and SimulinkLecture 111 MATLAB Desktop Profiler Improve code writing

MATLAB and SimulinkLecture 112 Basic Features Execute commands either by Write the code in command window Write code in a script file Execute script file by typing the file name in command window. Write code in a function file Execute function file by typing the file name in command window.

MATLAB and SimulinkLecture 113 Basic Features Addition+ Subtraction- Multiplication* Division / Store results in variables Case sensitive Maximum of 31 characters Must start with a letter

MATLAB and SimulinkLecture 114 Basic Features Example In command window >> 5+5 ans = 10 >> a=5+5 a = 10

MATLAB and SimulinkLecture 115 Basic Features No need to declare variables Any numerical value assign to a variable will be of class double Any character or sting assign to a variable will be of class character

MATLAB and SimulinkLecture 116 Basic Features The fundamental unit of data in MATLAB is the array Row 1 Row 2 Row 3 Col 4Col 3Col 2Col 1

MATLAB and SimulinkLecture 117 Basic Features Initializing variables Assign data in assignment statements var1 = 5+5; Input data from keyboard var1 = input(‘Enter a value’) Read data from file var1 = fread(fid, 5, 'uint8=>char')'

MATLAB and SimulinkLecture 118 Basic Features How to create arrays in MATLAB The ‘[]’ operator var1 = [1,2,3,4] % Row vector var1 = [1,2;3,4]% 2x2 array operator ‘;’ equal to new row Shortcut expression var1 = first:incr:last var1 = 1:1:4

MATLAB and SimulinkLecture 119 Basic Features Built-in functions var1 = zeros(2,4) var1 = ones(2,4) Useful MATLAB functions eye(n) Creates an nxn unity matrix size(var1) Returns the number of rows and columns in variable var1 length(var1) Returns the length of a vector var1, or the longest dimension if var1 is a 2-D array

MATLAB and SimulinkLecture 120 Basic Features Accessing elements in an array var1(2,2)= 5; Row 1 Row 2 Row 3 Col 4Col 3Col 2Col 1

MATLAB and SimulinkLecture 121 Basic Features Displaying output data The disp function disp(str) disp(‘This is displayed’) The fprintf function fprintf(format,data) fprintf(‘This the value of pi %f \n’,pi)

MATLAB and SimulinkLecture 122 Basic Features Scalar and Array Operations Remember the algebraic rules! Dot operator performs element by element operation. OperationMATLAB Form Array AdditionA+B Array SubtractionA-B Array MultiplicationA*B Array DivisionA/B = A*inv(B) Element by ElementA./B, A.*B, A.^B

MATLAB and SimulinkLecture 123 Example 2.1 What is the result of each expression

MATLAB and SimulinkLecture 124 Basic Features Introduction to plotting Plot the function y(x) for values of x between -5 and 5 >>X=-5:0.1:5 >>y=5*x.^2-2*x+5 >>plot(x,y)

MATLAB and SimulinkLecture 125 Basic Features Plot figur

MATLAB and SimulinkLecture 126 Basic Features Multiple plots >>X=-5:0.1:5 >>y1=sin(x) >>y2=cos(x) >>subplot(2,1,1),plot(x,y1) >>subplot(2,1,2),plot(x,y2)

MATLAB and SimulinkLecture 127 Basic Features

MATLAB and SimulinkLecture 128 Basic Features Line style, Line color, marker style and legend plot(x,y,s) s is a character string defining color, line style, marker style. See help plot for more information g=green. = point-- = dashed k=blacko = circle- = solid

MATLAB and SimulinkLecture 129 Example 2.3 Design a MATLAB program that reads an input temperature in degrees Fahrenheit, convert it to an absolute temperature in Kelvin, and write the result.

MATLAB and SimulinkLecture 130 Example 2.4 The figure shows a voltage source V=120 V with an internal resistance R s =50Ω supplying a load R L. Find the value of R L that will result in maximum power being supplied by the source. Plot the power supplied to the load as a function of the resistance R L +-+- RsRs RLRL V

MATLAB and SimulinkLecture 131 Example 2.4

MATLAB and SimulinkLecture 132 Branching Statements Logic and Relational Operators Logical OPERATORSRelational Operators OperatorOperationOperatorOperation ==Equal to&Logical AND ~=Not Equal To|Logical OR >Greater ThanxorLogical Exclusive OR <Less Then~Logical NOT =Less/Greater Then or Equal to

MATLAB and SimulinkLecture 133 Branching Statements The if Construct if control_expr_1 Statement elseif control_expr_2 Statement else control_expr_3 Statement end

MATLAB and SimulinkLecture 134 Example 3.4 Suppose that we are writing a program which reads in a numerical grade and assigns a letter grade to it according to: grade > 95A 95 ≥ grade 86 >B 86 ≥ grade 76 >C 76 ≥ grade 66 >D 66 ≥ grade 0 >F

MATLAB and SimulinkLecture 135 Branching Statements The switch Construct switch (switch_expr) case {csde_expr_1, csde_expr_2,…}, Statement case {csde_expr_3, csde_expr_4,…}, Statement otherwise, Statement end

MATLAB and SimulinkLecture 136 Example Determine whether an integer between 1 and 10 is even or odd, and print out an appropriate message.

MATLAB and SimulinkLecture 137 Loops The While loop while expression ……. code block ……. end

MATLAB and SimulinkLecture 138 Loops The for loop for index = expr Statement1 Statement2 …. end

MATLAB and SimulinkLecture 139 Loops Comparing Loops and Vectorization If possible use vectors. Loops slows down execution speed Calculate the square of every integer from 1 to Using a for loop can take up to 3 sec Using vectors takes sec

MATLAB and SimulinkLecture 140 Script file / Commando file When a script file executes the same result is made if all commands would be written in the command window A collection of statements All variables created will be stored in the same workspace. Have access to all variables in the workspace No input argument Returns no result Communication between script files through data stored in the workspace

MATLAB and SimulinkLecture 141 Suitable Exercises on this days topics 2.1, 2.4, 2.6, 2.10, 2.14, 2.16, (2), 3.4(3), 3.14(11), 3.15(12), 3.16(13) 4.24(19), 4.26(21), 4.29(22) The exercise numbers are referring to the book MATLAB Programming for engineers, third edition (second edition).