MATLAB Introduction MATLAB can be thought of as a powerful graphing calculator but with a lot more buttons! It is also a programming language, commands.

Slides:



Advertisements
Similar presentations
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Advertisements

Introduction to MATLAB 3 November Instructor: Andy Newman Office Hours: Stop by room 306 (main building) whenever
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
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.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
1 Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB ® to the reader. This.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
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.
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)
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
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.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
1 MatLab Basics Jae Hoon Kim Department of Physics Kangwon National University It contains hundreds of commands to do mathematics. Graph functions, solve.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
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.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
MATLAB Technical Computing Environment. MATLAB Matlab is an interactive computing environment that enables numerical computation and data visualization.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
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.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Introduction to Programming
ECE 1304 Introduction to Electrical and Computer Engineering
Whatcha doin'? Aims: To start using Python. To understand loops.
Arithmetic Operations
Release Numbers MATLAB is updated regularly
CS005 Introduction to Programming
Introduction to Programming
Lecture: MATLAB Chapter 1 Introduction
Introduction to MATLAB for Engineers, Third Edition
Variables, Expressions, and IO
Other Kinds of Arrays Chapter 11
Intro to PHP & Variables
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
User Defined Functions
Lecture 1: Introduction
StatLab Matlab Workshop
IDENTIFIERS CSC 111.
Number and String Operations
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Introduction to Programming
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
Digital Image Processing
Introduction to Programming
Introduction to MATLAB
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Experiment No. (1) - an introduction to MATLAB
Introduction to Programming
Matlab Basics Tutorial
Chapter 2 MATLAB Environment
Presentation transcript:

MATLAB Introduction MATLAB can be thought of as a powerful graphing calculator but with a lot more buttons! It is also a programming language, commands executed line by line MATLAB (matrix laboratory) is designed to work with matrices and vector data- your brain has to think in this way to code MATLAB This workshop is a blending of my old course for engineering students and a book called MATLAB for beginners: A gentle approach. A complete pdf version of an older edition is available online. http://ivut.iut.ac.ir/content/1059/MATLAB_for_Beginners.pdf

Your MATLAB window gives you clickable access to most of what you will need when using the software. >The command window is where you can type and execute lines of code >Current folder will show you all the files in the current folder (which is displayed above) >Workspace displays all the saved variables, their value and description >along the top, the “APPS” are also referred to in older text as toolboxes >PLOTS allows you to easily navigate the plot functionality, but you can also code this

You can customize this space: >You can add/delete windows on display. >If using the command window to execute code, it may be useful to add the command history “docked” to the display >you can explore preferences (the gear icon) to changes colour and appearance

You can customize how the windows are displayed as well by “grabbing them” with your mouse and moving them to shaded areas that appear

To adjust the current folder (normally defaults to MATLAB program folder, or the last accessed folder), you can click on the browse icon and select the folder of your choice. For today we will use your home directory and create a new folder (right click-new folder) called RDP_MATLAB*** **** Matlab has rules for file and variable naming- Must start with a letter, followed by letters or numbers or underscore, maximum 64 characters (excluding the .m extension), and must not be the same as any MATLAB reserved word. NO spaces, or other characters (ie. -,& etc) >>cd(‘filepath goes here’)

>>help and >>doc The most important command when learning MATLAB on your own is help Try typing in your command window “help sin” as shown below and press enter: Now try “help plot” This won’t work with any search term, but for built in functions of MATLAB You can also go straight to Mathworks tutorials by typing in “doc sin”

Start getting to know the command window Entering scalars and simple operations, try1: >> 2*3+5 What does the command window say? Look at your workspace, what do you see? Next try something a little more complex2: >> cos(60*pi/180) 3 Now look at creating a variable: >> x=4 What does the command window say now, how is it different? Look at your workspace, what do you see? Now let’s do something with that variable: >> 3/sqrt(2+x) 1 MATLAB order of command is important 2 Spend some time looking at built-in functions like cos, pi, sqrt 3 MATLAB defaults to radians with angles

Getting to know the command window Try some more operations by copy/paste: 1.) Perform the addition 7+9 2.) Perform subtraction of 16-10 3.) Perform multiplication 2*9 4.) Perform division 12/3 5.) Perform the exponential 3^5 6.) Perform the multiplication of 3*-5 7.) Perform the exponential of (-3)^5 8.) Perform the exponential of -3^5 9.) Perform multiple operations (4.5+1.5)/2 10.) Perform multiple operations (4.5+1.5)/2 –2*(7^4)/100

Getting to know the command window The Semicolon: In your command window, type: >> y=30; >> z=8; What is different about this display? Look at your workspace again. Semicolon ends a line of execution. Try typing: >> x=2; y-z; Check out your workspace: More complex variable manipulation with mutliplication: >> w=4*y+3*z MATLAB is case sensitive! Try typing the below, (you should get an error!) >> w=4*Y+3*z To find all the variables used (defined) in a session, type in >>who Now try giving the variable Y a value: >> Y=20; check your workspace, and try the command again:

Save, clear and clc Now that you can add variables, how about deleting them? Try: >>clear x , what happened to workspace? To clean upi your command window, without deleting variables, type: >>clc What about clearing all variables? Try >>clear all What about saving variables? Define two variables a=3, b=5 in your command window. Then try typing the following code, and check your current folder. >>save myFile a b Now, let’s start from scratch, >> clear a b Now try: >>load myFile

More Arithmetic operations π – type pi ε – type eps Absolute value- abs() Square root- sqrt() You can find loads more coded versions of operations by looking up Arithmetic operators in the Mathworks help

Variables’ Rules Summary The following are the MATLAB rules for naming variables: >MATLAB is case sensitive with respect to variable names >Letters and digits allowed >Variable names must start with a letter (not numbers) >You may have up to 31 characters to name a variable >Punctuation signs are not allowed, including spaces >The underscore “_” is allowed but can’t be first >Don’t use built-in variable names such as “ans”

Using built-in functions- Be aware that the built-in constants (and even functions) can be overwritten by the user. Try the following and make sense of the outcomes: >> j = 100; >> j^2 >> clear j

Types of variables Scalars, defined as integers, doubles Characters or Strings Arrays or Matrices Besides integer values and reals, MATLAB can also hold complex numbers and text, and, all of these different value types can be stored in matrices and vectors. Matrices will be introduced in later sections.

Trying out variables Remember when we gave variable Y a value: >> Y=20 for w=4*Y+3*z; check your workspace, and try the command again, but this time instead of w=, use: >> the_answer_is=4*Y+3*z Try defining the following variables: >>cost=100; >>sale_price=120; >>profit=sale_price – cost Numbers are displayed with four decimals. Try: >> fraction=7/3 However, MATLAB stores numbers internally with about 16 digits. You can display these by formatting your output. Type: >>format long then try typing >>fraction=7/3 You can reformat back to four decimal places by >>format short To look at all the options you can select, try >>help format

Commenting/Annotating Code MATLAB code should not just be readable by MATLAB itself, but also by human readers. Useful to annotate your code with comments whilst you are writing. Express intention of code section, meaning of variables, underlying asusmptions. The symbol % is used to indicate text which is not intended for MATLAB but for the reader (comments) Try typing >>% This is a comment to explain to my code

Symbolic Math You may also use symbolic variables For examples, defined the variables x and y as follows: >>x=1/2 >> y=2/3 Then type: >>sym(x) >>sym(y) Now arithmetic operations can be performed on these symbolic variables. Consider the following: >>z=sym(x-y) In the above, z is automatically given symbolic variable type (check workspace) The important thing is to start each operation or calculation with the sym command. If you want to convert back to a number value you can use the double command. Tyr: >>double(z)

Variables exercises 1. Perform the operation 2*3+7 and store the result in the variable w. 2. Let x = 5.5 and y = -2.6. Calculate the value of the variable z = 2x-3y. 3. In Exercise 2 above, calculate the value of the variable w = 3y – z + x/y. 4. Let r = 6.3 and s = 5.8. Calculate the value of the variable final defined by final = r + s - r*s. 5. In Exercise 4 above, calculate the value of the variable this_is_the_result defined by this_is_the_result = r^2 – s^2. 6. Define the three variable width, Width, and WIDTH equal to 1.5, 2.0, and 4.5, respectively. Are these three variables identical? 7. Write the following comment in MATLAB: This line will not be executed.

Exercises continued 8. Define the values of the variables y1 and y2 equal to 7 and 9 then perform the calculation y3 = y1 – y2/3. (Note: 2 in the formula is a subscript and should not be divided by 3). 9. Perform the operation 2*m – 5. Do you get an error? Why? 10. Define the variable centigrade equal to 28 then calculate the variable fahrenheit defined by fahrenheit = (centigrade*9/5) + 32. 11. Use the format short and format long commands to write the values of 14/9 to four decimals and sixteen digits, respectively. 12. Perform the who command to get a list of the variables stored in this session. 13. Perform the whos command to get a list of the variables stored in this session along with their details. 14. Calculate symbolically the area of a circle of radius 2/3 without obtaining a numerical value. No Units are used in this exercise. 15. In Exercise 14 above, use the double command to obtain the numerical value of the answer.