CSE123 Introduction to Computing Lecture 2 Introduction to MATLAB.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Fall 2006AE6382 Design Computing1 Numeric Representation in a Computer Learning Objectives Understand how numbers are stored in a computer and how the.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Welcome to EGR 106 Foundations of Engineering II Course information Today’s specific topics: – Computation and algorithms – M ATLAB Basics Demonstrations.
CSE123 Introduction to Computing
Introduction to MATLAB 7 for Engineers
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Chapter 2 Data Types, Declarations, and Displays
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Basic Input/Output and Variables Ethan Cerami New York
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.
COMPUTER SCIENCE I C++ INTRODUCTION
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
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.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Representing numbers and Basic MATLAB 1. Representing numbers  numbers used by computers do not behave the same as numbers used in mathematics  e.g.,
Input, Output, and Processing
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
CMPS 1371 Introduction to Computing for Engineers MatLab.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Introduction to Programming with RAPTOR
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Figure 2.1a Evaluating Expressions To evaluate an algebraic expression, we may substitute the value(s) in place of the variable(s) and evaluate the numeric.
EGR 115 Introduction to Computing for Engineers Introduction to MATLAB Friday 29 August 2014 EGR 115 Introduction to Computing for Engineers.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
MATLAB The name of MATLAB stands for matrix laboratory. Starting a MATLAB Session -On Microsoft® Windows® platforms, start the MATLAB program by double-clicking.
ECE 1304 Introduction to Electrical and Computer Engineering
Topics Designing a Program Input, Processing, and Output
Release Numbers MATLAB is updated regularly
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chapter 2 - Introduction to C Programming
Guide To UNIX Using Linux Third Edition
Chapter 2 - Introduction to C Programming
MATLAB DENC 2533 ECADD LAB 9.
Chapter 2 - Introduction to C Programming
WEB PROGRAMMING JavaScript.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
INTRODUCTION TO MATLAB
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Topics Designing a Program Input, Processing, and Output
Experiment No. (1) - an introduction to MATLAB
Topics Designing a Program Input, Processing, and Output
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Presentation transcript:

CSE123 Introduction to Computing Lecture 2 Introduction to MATLAB

MATLAB Matlab provides a technical computing environment designed to support the implementation of computational tasks. Matlab is an interactive computing environment that enables numerical computation and data visualization.

MATLAB Matlab is an effective tool. –very simple numerical or statistical calculations, –some complex statistics, –solve simultaneous equations, –make a graph, or run and entire simulation program, Matlab can solve –problems in applied mathematics, physics, chemistry, engineering, finance – almost any application area that deals with complex numerical calculations.

MATLAB Running MATLAB Double-click on the Matlab icon or select Matlab from Start/Programs MATLAB Windows –Command Window –Workspace –Current Directory –Command History

Numbers Matlab represents numbers in two forms, fixed point and floating point. Fixed point: Decimal form, with an optional decimal point. For example: Floating point: Scientific notation, representing m x 10 e For example: x 10 5 is represented as e5 The number has two parts: mantissa m: fixed point number (signed or unsigned), with an optional decimal point ( in the example above) exponent e: an integer exponent (signed or unsigned) (5 in the example). Mantissa and exponent must be separated by the letter e (or E).

Operators “>>” is supplied by Matlab, indicates beginning of the command. ans = following the completion of the command with the Enter key marks the beginning of the answer.

Operators Try following operations: >> >> 4*22 + 6*48 + 2*82 >> 4 * 4 * 4 >> 4^3 >> 56/8 >> 8\56

Precedence of operations (order of evaluation) There are rules about the order of operations 1. Parentheses, innermost first 2. Exponentiation (^), left to right 3. Multiplication (*) and division (/ or \) with equal precedence, left to right 4. Addition (+) and subtraction (−) with equal precedence, left to right When operators in an expression have the same precedence the operations are carried out from left to right. Thus, 3 / 4 * 5 is evaluated as ( 3 / 4 ) * 5 and not as 3 / ( 4 * 5 ).

Precedence of operations (order of evaluation) Examples:

Some built-in functions FunctionSymbolExample Sinus sin()sin(pi) Cosinus cos()cos(pi) Tangent tan()tan(pi) inv sinus asin()asin(0) inv cosinus acos()acos(0) inv tangent atan()atan(1) FunctionSymbolExample Eksponential, e x exp()exp(2) Natural Logarithm ln(x) log()log(10) Logarithm based 10, log log10()log10(10) Square root,  x sqrt()sqrt(25) Absolute, |x| abs()abs(x) Modulus Remainder of x/y rem(x,y)rem(7,2) (=1)

Variables and Assignment Statements Assignment statement: variable = number variable = expression variable = input(‘enter a number’) Variable names Must start with a letter May consist only of the letters a-z, digits 0-9, and the underscore character (_) May be as long as you would like, but Matlab only recognizes the first 63 characters case sensitive: items, Items, itEms, and ITEMS are all different variable names.

Variables and Assignment Statements Example: >> mterm = 60 >> final=80; >> quiz=60; >> grade = 0.5*midterm+0.1*quiz+0.4*final Variables: mterm,final,quiz,grade Results displayed and stored by variable name Semicolon at the end of a line (as in the line >> final=80;) tells Matlab to evaluate the line but not to display the results

Variables and Assignment Statements Examples more… >> x=5; >> y=x+5; >> x=2; y is still 10 not 7 you have to run >> y=x+5 again to obtain new value of y. >> z=z+2 is a correct assignment in MATLAB. If you have not supplied a value for xx, Matlab will return a syntax error: >> y=xx+5 ??? Undefined function or variable ’xx’.

Variables and Assignment Statements Examples more… TC=5/9*(TF-32) Sometimes writing an equation in multiple statements makes the equation more understandable numerator = s^2 + 4*s + 13; denominator = s^3 - 2*s^2 + 4*s + 5; H = numerator/denominator;

Example - Solving for quadratic roots 2s s + 12 = 0 find roots of the quadratic equation. >> a =2; >> b =10; >> c =12; >> disc = b^2-4*a*c; >> x1 = (-b + sqrt(disc)) /(2*a) >> x2 = (-b - sqrt(disc)) /(2*a) x1 = -2 x2 = -3

input() INPUT Prompt for user input. X=input(‘enter a number’) enter a number2 X = 2 Enter character strings as follows Name=input(‘enter your name :’,‘s’) enter your name :ali Name = ali

disp() DISP There are two general forms of the command disp that are useful in displaying results and annotating them with units or other information: 1.disp(variable): Displays value of variable without displaying the variable name. 2.disp(string): Displays string by stripping off the single quotes and echoing the characters between the quotes. String: A group of keyboard characters enclosed in single quote marks (’). The quote marks indicate that the enclosed characters are to represent ASCII text. >> temp=78; >> disp(temp); disp(’degrees F’) 78 degrees F

Display Options There are several commands that can be used to display variables with more control over the form of the display.

Commands involving variables: who: lists the names of defined variables whos: lists the names and sizes of defined variables clear: clears all variables, resets default values of special variables clear var: clears variable var clc: clears the command window, homes the cursor (moves the prompt to the top line), but does not affect value of variables. clf: clears the current figure and thus clears the graph window. Use commands….

Computational Limitations In Matlab, numbers are typically represented in a floating-point representation conforming to a standard established by the IEEE in In the IEEE double-precision standard used by Matlab, there are 53 bits (approx. 15 significant digits )in the mantissa and 11 bits in the exponent (m x 2 e ), for a total of 64 bits to represent a scalar number. This provides a range of values extending from 10 −308 to

Computational Limitations Two Matlab functions, realmax and realmin, display the largest and the smallest numbers, respectively. >> realmax ans = e+308 >> realmin ans = e-308

Command reuse and editing Press the up arrow cursor key (↑) to scrolls backward through previous commands. Press Enter to execute the selected command. The down arrow cursor key (↓) scrolls forward through commands The left (←) and right arrow (→) cursor keys move within a command at the Matlab prompt, allowing the command to be edited. The mouse can also be used to reposition the command cursor, by positioning the mouse cursor and pressing the left mouse button.

Command reuse and editing Other standard editing keys, such as delete Del, backspace BkSp, home Home, and end End, perform their commonly assigned tasks. Once a scrolled or edited command is acceptable, pressing Enter with the cursor anywhere in the command tells Matlab to process it. Escape key Esc erases the current command at the prompt. Windows copy and paste operations can be used

Getting Help help – On-line help, display text at command line help, by itself, lists all help topics help (topic)- provides help for the specified topic help (command)- provides help for the specified command help help – provides information on use of the help command helpwin – On-line help, separate window for navigation. helpdesk – Comprehensive hypertext documentation and troubleshooting help ops: help about operators and special characters F1 + topic and help tab from File menu.

Interrupting and Terminating Matlab Ctrl+C : Interrupts (aborts) processing, but does not terminate Matlab. quit: Terminates Matlab exit: Terminates Matlab Select Exit under File menu : Terminates Matlab