Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = 2 -3 4 1 6 -3 -5 1 2 B = 10 4 3 >> X = A\B X = 1.2609 2.2261 3.5391.

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Advertisements

Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Lecture 7 Debugging Code & Data Import/Export © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
Welcome to EGR 106 Foundations of Engineering II Course information Today’s specific topics: – Computation and algorithms – M ATLAB Basics Demonstrations.
EGR 106 – Truss Design Project (cont.) Truss design programs Graphical interface tools in Matlab Saving and loading data Formatted output Project Assignment.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
EGR 106 – Week 8 Data Files & Functions Interacting with Data Files Functions – Concept – Examples and applications Textbook chapter ,
Introduction to MATLAB
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Matlab® refresher Your objective: to dominate! My objective: to help you dominate!
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.
Digital Image Processing Lecture3: Introduction to MATLAB.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
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
M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files called M- files. M-files are.
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.
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 4.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (3): MATLAB Environment (Chapter 1)
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
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.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Copyright © The McGraw-Hill Companies, Inc. Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 1 An Overview of MATLAB.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Technical Computing Environment. MATLAB Matlab is an interactive computing environment that enables numerical computation and data visualization.
1 Input / Output Input – reads/gets data for the program Output – the product, after processing Both can be: interactive I/O (while program is running)
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 &
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
ENG College of Engineering Engineering Education Innovation Center 1 More Script Files in MATLAB Script File I/O : Chapter 4 1.Global Variables.
MCE 372 Engineering Analysis MATLAB Review. M ATLAB – What Is It ? Where Is It? Name is from matrix laboratory Powerful tool for – Computation and visualization.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
GENERATION OF RANDOM NUMBERS
EGR 115 Introduction to Computing for Engineers Introduction to MATLAB Friday 29 August 2014 EGR 115 Introduction to Computing for Engineers.
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.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
M ATLAB – What Is It ? Name is from matrix laboratory Powerful tool for – Computation and visualization of engineering and science mathematics – Communication.
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.
Release Numbers MATLAB is updated regularly
Introduction to MATLAB for Engineers, Third Edition
MATLAB DENC 2533 ECADD LAB 9.
Lecture 1: Introduction
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
Lecture 2 Introduction to MATLAB
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
MATLAB How to use (using M-files)
Digital Image Processing
Matlab.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Experiment No. (1) - an introduction to MATLAB
Scripts In Matlab.
Your objective: to dominate! My objective: to help you dominate!
Presentation transcript:

Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X = >> 2*X(1) -3*X(2) + 4*X(3) ans = 10

Element by Element Operators Multiplication.* x(n) = A(n)*B(n) Division./x(n) = A(n)/B(n) Exponentiation.^x(n) = A(n)^y(n) Left Division.\ x(n) = B(n)/A(n) x = A.*B x = A./ B x = A.^ y x = A.\B

EGR 106 – Week 4 – Files Saving commands as simple “programs” Using Matlab’s editor Useful script commands Saving and reading data Textbook chapter 4, pages

So far: Commands typed in the command window: – Executed by pressing “enter” – Edited using the arrow keys or the history window Results are temporary: – Rerun commands – Keep a “diary” file Scripts or m files Data files

Script Concept A file containing Matlab commands – Can be re-executed – Are easily changed Commands are executed in sequence – Results appear in the command window (or use ; ) – File is executed by typing its name (without.m) Can be created using any text editor –.m extension – Listed in current directory window

Matlab’s Built-in, Color Editor: Can create a new file or open an existing m file (icons or click on file name) Color used to aid in file creation (command types, typos)

– typical windows menu – line numbers – “run” button or F5 – debug capability – comment lines – note use of semicolons – note use of colors

Where Matlab Looks for Things 1. As a variable in the current workspace 2. As a built in function 3. As an m file in the “current directory”

4. Down the “search path” of directories Conclusion – use unique names

How Scripts Get Data From arrays in the current workspace From arrays defined in the script Using the “input” command: – Numeric: x = input(' how many? ') – String: x = input(' name? ', 's')

How Scripts Shows Data Command of the array name Using the display command: – Existing array – disp(x) – Text disp(' The task is done ')

Example : Note that disp shortens the resulting output by dropping the array name and removing blank lines

Formatted print command fprintf(format,data) – Combines text and data – Allows complete control of the output – format is a string (in quotes) containing text and control commands (using \ or %) – like in C – An example: \n = new line %d = put data here The data itself

Escape characters: – New line ( \n ), backspace ( \b ), tab ( \t ), … Conversion codes for data: – Decimal ( %d ), character ( %c ), exponential notation ( %e ), fixed precision ( %f ), … – Can add field width and precision information: 5 characters wide, 2 after the decimal point

fprintf works element-by-element on array data: \n added for line return

fprintf can also write to a file: fid = fopen( 'name', 'w' ) fprintf(fid,format,data) … fclose(fid) – fid is a variable name to specify which file – name is the name of the file w indicates “write”

Example Scripts

Matlab Data Files (not in the text) Types: – ascii = regular text files –.mat = Matlab’s proprietary format (multiple variables)

Saving data: – save filename – save filename array1 array2 – save filename –ascii Reading in (loading) data: – load filename – load filename array1 array2 – load filename –ascii

Debugging Errors Syntax errors: Note red text = bad news

Run-time errors: inf or NaN results Note black text = is okay

Logical errors in your program – hard to find – Example: quadratic equation solver – But x 2 +2x+1 = (x+1) 2  x = -1 Use the built-in debugger Missing parentheses

New Homework Procedure Electronic submission via One single m file: executing it should – Present solutions in order – Pause in between problems – Use clear, clc, and clf to clear out old data, results, and/or plots – Use ; to suppress unnecessary outputs – Name file as yourlastname_4.m