Lab 1 - Worksheet Spring 2013

Similar documents
AMS 27L LAB #1 Winter 2009

MATLAB QUICK START TUTORIAL

Sketchify Tutorial Properties and Variables. sketchify.sf.net Željko Obrenović

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

Introduction to Engineering gii

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

Introduction to Matlab

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Introduction to MatLab. Introduction to MatLab K. Craig 1

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

Consider this m file that creates a file that you can load data into called rain.txt

To start using Matlab, you only need be concerned with the command window for now.

What is Matlab? The command line Variables Operators Functions

User manual. Version 9.2.0

TECH TIP VISION Calibration and Data Acquisition Software

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Chapter 1 Introduction to MATLAB

Introduction to MATLAB

Welcome to EGR 106 Foundations of Engineering II

2.0 MATLAB Fundamentals

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Introduction to MATLAB

Matlab Programming Introduction 1 2

Solving Systems of Equations Using Matrices With the TI-83 or TI-84

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

Identity Matrix: >> eye(3) ans = Matrix of Ones: >> ones(2,3) ans =

Chapter 2. MATLAB Basis

LinReg 2.06 Manual. DePauw University: Physics Department 120 Physics I and 130 Physics II

Introduction to MATLAB

Matlab Tutorial, CDS

Basic MATLAB Tutorial

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Introduction to MATLAB

LAB 1 General MATLAB Information 1

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Mathematical Operations with Arrays and Matrices

Summary of basic C++-commands

Introduction to MATLAB 7 for Engineers

Digital Image Analysis and Processing CPE

Chapter 3. built in functions help feature elementary math functions data analysis functions random number functions computational limits

1 Week 1: Basics of scientific programming I

Introduction to MATLAB Programming

EGR 111 Introduction to MATLAB

MatLab Just a beginning

Programming in MATLAB

PART 1 PROGRAMMING WITH MATHLAB

For example, the system. 22 may be represented by the augmented matrix

Introduction to MATLAB Practical 1

A Short Introduction to Matlab

Goals for This Lecture:

Introduction to MATLAB. Dr./ Ahmed Nagib Elmekawy Mechanical Engineering department, Alexandria university, Egypt Spring 2017.

MATLAB Quick Reference

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

Table of Contents. Basis CEMTool 7 Tutorial

EP375 Computational Physics

ENGR 105: Introduction to Scientific Computing. Dr. Graham. E. Wabiszewski

Numerical Analysis First Term Dr. Selcuk CANKURT

What is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions

USER-DEFINED ELEMENT IN ZMAN TM

Chapter 4: Basic C Operators

CS1010E Lecture 3 Simple C Programs Part 2

MATLAB Tutorial The Basics

MAT 343 Laboratory 2 Solving systems in MATLAB and simple programming

General MATLAB Information 1

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

Chapter 3 Functions and Files

Lecture 2: Variables, Vectors and Matrices in MATLAB

Process Optimization

Introduction to MATLAB 7 for Engineers

Reference manual. PreFEED Corporation

ME 121 MATLAB Lesson 01 Introduction to MATLAB

A Quick Tutorial on MATLAB. Zeeshan Ali

Basic stuff -- assignments, arithmetic and functions

Introduction to Matlab

Exercise Set Decide whether each matrix below is an elementary matrix. (a) (b) (c) (d) Answer:

Lecture 1: What is MATLAB?

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services

A 30 Minute Introduction to Octave ENGR Engineering Mathematics Tony Richardson

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

Introduction to MATLAB 7 for Engineers

C++ Overview. Chapter 1. Chapter 2

Introduction to MATLAB for Engineers, Third Edition

Introduction. Summary of Contents Section 1 of this document discusses how to use MATLAB as a scalar calculator, and section 2 how

MATH 423 Linear Algebra II Lecture 17: Reduced row echelon form (continued). Determinant of a matrix.

INTRODUCTION TO MATLAB FOR ENGINEERING STUDENTS. David Houcque Northwestern University

Some elements for Matlab programming

Brief Matlab tutorial

A General Introduction to Matlab

Dr Richard Greenaway

MATELECT PDsoft v1.00

Introduction to MATLAB for Engineers, Third Edition

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD

1.1 ABOUT MATLAB and MATLAB GUI (Graphical User Interface)

Functions and Inverses ID1050 Quantitative & Qualitative Reasoning

Transcription:

Math 300 UMKC Lab 1 - Worksheet Spring 2013 Learning Objectives: 1. How to use Matlab as a calculator 2. Learn about Matlab built in functions 3. Matrix and Vector arithmetics 4. MATLAB rref command 5. Row operations on matrices 6. Solving linear systems with Matlab 7. How to import and export data between Excel to Matlab Basic Operations in Matlab a. For Numbers & Matrices we have: + (addition) - (subtraction) * (multiplication) / (division) (power) b. For Vectors we have + (addition) - (subtraction).* (multiplication)./ (division). (power) Symbols pi (p = 3.1416) i (complex number e.g. 2+3i) NaN (not a number e.g. 0/0) inf (infinity) 1. Matlab as a calculator: Matlab can be used as a sophisticated calculator. Please enter the following commands followed by the return key. Important note: use parenthesis to specify the order of operation >> 3 4 5 >> 3 (4 5) >> 18/3 + 2 2 >> 18/(3 + 2 2) 1

2. Built in functions: Matlab has several built-in functions. Type elementary math in Matlab Help to get the list of elementary functions. Examples are: (a) Exponential and logarithmic functions: exp(x), log(x), log10(x), sqrt(x), (b) Trigonometric functions: sin(x), cos(x), tan(x), asin(x), acos(x), atan(x) (c) Hyperbolic functions: sinh(x), cosh(x), tanh(x), asinh(x), acosh(x), atanh(x) >> a = cos(3.14) cos(pi) >> cosh( 4) >> atan(3 pi 4) 3 Vectors & Matrices: Entries of a row vector are separated by spaces or commas. Entries of a column vector are separated by semicolons. For instance, we may enter the following vectors in the command window. >> a = [2 3 4 7] >> b = [2; 3; 4; 7] >> length(a) >> c = a >> d = linspace(0, 1, 12) >> logspace(1, 2, 7) >> x = 1 : 2 : 20 >> mean(x) >> min(x) >> max(x) >> y = x >> z = x. y >> w = x./y For Matrices, each row is separated by semicolon. Example: 2

>> M = [2 3 5; 4 5 9; 0 12 23] >> size(m) >> A = M >> M(2, 2) >> M(:, 2) >> M(3, 1 : 3) >> inv(m) >> K = zeros(3, 4) >> G = ones(4, 4) >> I = eye(4) >> L = I G >> P = L G ones(4, 3) K 4. rref command: We want to solve the following linear using rref command. 5x + 4y + 3z + 3u = 11 2y + z u 4w = 1 3x z 4w = 10 4x + 5y 4w = 3 4x + 12y 4u 4w = 0 Step1: Generate matrix A by entering >> A = [5 4 3 3 0; 0 2 1-1 -4; 3 0-1 0-4; -4 5 0 0-4; -4 12 0-4 -4] Step 2: Generate vector b by entering >> b = [11; -1; 10; -3; 0] Step 3: Form the augmented matrix M and transform it into an rref matrix by entering >> M = [A, b] >> rref(m) 3

Step 4: Find the solution(s) if any. 5. Row operations on matrices: We want to solve the following linear system using row operations. x + 4y + 3z = 11 2x + y z = 1 3x y 4z = 10 a ) First we need form the augmented matrix. Note that in Matlab rows are divided by semicolon. This is done as follows. >> A = [1 4 3; 2 1-1; 3-1 -4] >> b = [11; -1; 10] >> M = [A, b] Alternatively we may enter a matrix just the way it is written. For instance, generates the same matrix A. >> A = [1 4 3 2 1-1 3-1 -4] b ) We need to transform the first column into a unit column. Hence we multiply the first row by -2 and add it to the second row. Also we multiply the first row by -3 and add it to the third row. In MATLAB the ith row of Matrix M is indicated by M(i, :). Enter >> M(2, :) = -2*M(1, :) + M(2, :) >> M(3, :) = -3*M(1, :) + M(3, :) c ) Now, we need to get the leading 1 into the entry (2,2) of the new augmented matrix. This is done by multiplying the second row by -1/7. 4

>> M(2, :) = (-1/7)*M(2, :) d ) To make the entry (3,2) zero, we add 13 times of the second row to the third row. >> M(3, :) = 13*M(2, :)+ M(3, :) e ) The last row indicates that the system does not have any solution and there is no need to continue the row operations. Note: To obtain the row reduced model we may directly use rref command, which stands for row-reduced echelon form. To apply this to the last example, enter >> M = [A, b] >> rref(m) 6. Matlab built-in solver: We may use linsolve(a,b) to solve systems of linear equations. Note that A is the matrix of coefficients and b is a column representing the right hand side of the equations. In other words the linear system of equations is represented by AX=b, where X is the solution vector. Noting that the above system does not have any solution by entering >> linsolve(a,b) As expected, we get Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 9.251859e-018. Exercise 1. Consider the following system of linear equations. 3x 2y + 8z = 9 2x + 2y + z = 3 x + 2y 3z = 8 a ) Form A and b matrices and by entering M = [A, b] and rref(m) obtain the row reduced form of the augmented matrix M. b ) Enter linsolve(a,b) to solve the system. You should get to x = 3, y = 4 and z = 1. 5

Exercise 2. Repeat the last problem for the following system of linear equations. 3x 1 + 6x 2 + 12x 3 9x 4 6x 5 = 3 4x 1 8x 2 10x 3 + 18x 4 + 6x 5 = 16 2x 1 4x 2 5x 3 + 9x 4 + 6x 5 = 11 Note that rref(m) clearly shows that the system has infinitely many solutions and linsolve(a,b) returns only a particular solution. 7. Matlab Data Import and Export: a ) Download the Excel file BankLoan.xls into your desktop. This is a hypothetical data file that contains financial and demographic informationon 700 past and prospective customers. b ) Open the file to see the available information about each costumer. c ) Start Matlab by clicking on the Matlab icon. d ) On the file menu choose import data, change the file types to all files and give specific path of BankLoan.xls. Click on Finish. Matlab generates a Matrix called data with the size 700 9. e ) The first column is the age of costumers. To obtain basic stats of the age enter datastats(data(:,1)) in the command window this will return the following statistical information. Num (The number of data values); Max (The maximum data value); Min (The minimum data value); Mean (The mean value of the data); Median (The median value of the data); Range (The range of the data); Std (The standard deviation of the data). f ) Repeat the last section to obtain stats of column 5 which is annual income of costumers. g ) To export data into an Excel enter xlswrite( newbankloan.xls,data). The file is saved in the current Matlab directory. 6