Can be put into the matrix form of Ax=b in this way:

Similar documents
Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Lab 1 Intro to MATLAB and FreeMat

INTRODUCTION TO MATLAB

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Math 7 Elementary Linear Algebra PLOTS and ROTATIONS

AN INTRODUCTION TO MATLAB

Programming in Mathematics. Mili I. Shah

NOTE: If you are new to TABLE and GRAPH modes you may find it beneficial to first work through the worksheet 'Self-Guided_9860_TABLE-GRAPH'.

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Introduction to Matlab

Matlab Introduction. Scalar Variables and Arithmetic Operators

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.

Laboratory 1 Introduction to MATLAB for Signals and Systems

x = 12 x = 12 1x = 16

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in

Foundations of Math II

Introduction to Matlab

1. Register an account on: using your Oxford address

University of Alberta

Total Number of Students in US (millions)

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li

This assignment is due the first day of school. Name:

Matrix Inverse 2 ( 2) 1 = 2 1 2

Introduction to MATLAB

Getting Started with MATLAB

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

LAB 2: Linear Equations and Matrix Algebra. Preliminaries

A 30 Minute Introduction to Octave ENGR Engineering Mathematics Tony Richardson

AMS 27L LAB #2 Winter 2009

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

EGR 111 Introduction to MATLAB

TUTORIAL 1 Introduction to Matrix Calculation using MATLAB TUTORIAL 1 INTRODUCTION TO MATRIX CALCULATION USING MATLAB

Class #15: Experiment Introduction to Matlab

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

Laboratory 1 Octave Tutorial

A quick Matlab tutorial

A Guide to Using Some Basic MATLAB Functions

Years after US Student to Teacher Ratio

Table of Contents. Basis CEMTool 7 Tutorial

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

A Brief Introduction to MATLAB

TWO DIMENSIONAL ARRAY OR MATRIX common name scores Defined as scores[10][5] IE 10 rows x 5 columns showing name of each position; some values below

Getting Started with MATLAB

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

Matlab Tutorial: Basics

Introduction to MATLAB

MATLAB TUTORIAL WORKSHEET

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

1 Introduction to Matlab

Introduction to PartSim and Matlab

LabVIEW MathScript Quick Reference

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

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Basic Simulation Lab with MATLAB

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

EE 301 Lab 1 Introduction to MATLAB

Introduction to Scientific Computing with Matlab

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

Maths for Signals and Systems Linear Algebra in Engineering. Some problems by Gilbert Strang

Dr Richard Greenaway

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

Mini-Project 1: The Library of Functions and Piecewise-Defined Functions

Quadratics Functions: Review

A = [1, 6; 78, 9] Note: everything is case-sensitive, so a and A are different. One enters the above matrix as

Lab 5 Nodal and Mesh Analysis

Lab 1 Introduction to MATLAB and Scripts

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

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

1-- Pre-Lab The Pre-Lab this first week is short and straightforward. Make sure that you read through the information below prior to coming to lab.

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Colorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB

Matrices 4: use of MATLAB

MATLAB and Numerical Analysis

An Introduction to Numerical Methods

ECE-205 Lab 1. Introduction to Simulink and Matlab

Section 4.4: Parabolas

Lab P-1: Introduction to MATLAB. 3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

MATLAB Demo. Preliminaries and Getting Started with Matlab

EE 350. Continuous-Time Linear Systems. Recitation 1. 1

Fall 2015 Math 337. Basic MatLab

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

American International University- Bangladesh Faculty of Engineering (EEE) Control Systems Laboratory

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

Unit: Quadratic Functions

Graphs of Equations. MATH 160, Precalculus. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Graphs of Equations

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

Matlab and Octave: Quick Introduction and Examples 1 Basics

Solve the matrix equation AX B for X by using A.(1-3) Use the Inverse Matrix Calculator Link to check your work

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01

EE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext Objective. Report. Introduction to Matlab

Lecture 2: Variables, Vectors and Matrices in MATLAB

Basic Graphs. Dmitry Adamskiy 16 November 2011

Transcription:

Pre-Lab 0 Not for Grade! Getting Started with Matlab Introduction In EE311, a significant part of the class involves solving simultaneous equations. The most time efficient way to do this is through the use of Linear Algebra. Matlab provides a great environment to solve this type of problem and can save many hours of homework time. This lab will acquaint you with the basic tools to solve a system of equations using Matlab as well as basic plotting functions. Linear Algebra Basics A given a system of linear equations: (Equation 1) (Equation 2) (Equation 3) Can be put into the matrix form of Ax=b in this way: The terms A and b are assumed known, while the x terms are assumed to be unknown. A is also known as the coefficients of x. Given a full rank-square matrix, A, one can solve for x using linear algebra x = A -1 b where A -1 is the inverse of the A matrix. (It is suggested that one should remind themselves of the meaning of fullrank, linear dependent, and linear independent, as well as basic linear algebra and matrix multiplication.) Matlab is a program that works with vectors or matrices. Hence, it is perfect for easily solving linear equations. One only needs to learn how to enter the matrices. The matrix equation above would be entered into Matlab as shown below. Notice that spaces separate the columns and a semicolon separates rows. The semicolon at the end of a line dictates whether or not the result will print - ; to suppress the printing, no ; to print. The inverse of a matrix is found by using the function inv(). Please note that if the system of equations is not linearly independent, the inv function will produce an error. In most homework problems, this means you need to look for another equation. The inv function will also fail if A is not square. A = [a11 a12 a13; a21 a22 a23; a31 a32 a33]; b = [b1; b2; b3]; x = inv(a)*b One should also remind one s self of how to solve for a matrix inverse for 2x2 and 3x3 matrices by hand, e.g. Row Operations (this is the easier method) or Cramer s rule, -- for tests and quizzes. Elaine Linde Page 1 Fall 2009

Using Matlab To open Matlab on the school lab computers go to : Start Programs Dept EE Matlab R2009a The opening window will appear as shown in Figure 1. Figure 1: Main Matlab Screen Executing commands Matlab does not compile a whole program before executing it. It compiles and runs it line by line. There are a couple of ways to use the Matlab command window to execute commands. The most basic is just to type the command and hit return. A series of lines can also be cut and pasted to the command line for another editor like Notepad. However, the most convenient way is to make a file to be executed. These are referred to as m-files because they are stored as filename.m. In fact, all functions built into Matlab are just m-files. The easiest way to do this is to take advantage of Matlab s editor. To activate the editor, select File, New, Blank M-file as shown in Figure 2. The editor screen will appear as shown in Figure 3. Elaine Linde Page 2 Fall 2009

Figure 2: Activating the editor to create an m-file Figure 3: Matlab Editor Elaine Linde Page 3 Fall 2009

File Names The rules for naming files in Matlab are: Do not use spaces (ex. use Lab4.m or Lab_4.m not Lab 4.m) Do not start with a number (ex. use Lab4.m not 4lab.m) Do not name things the same as a Matlab function (ex. exp, mean, sqrt), i.e. check to make sure your possible name is not already a Matlab function! An Example of a Problem with Simultaneous Equations Given the following system of linear equations where the R s refer to known resistors and the i s refer to unknown currents. (R1+R2+R3)i1 + (-R2)i2 +(-R3)i3 = 12 (-R2)i1 + (R2+R4)i2 +(-R4)i3 = -5 (-R3)i1 + (-R4)i2 +( R3+R4+R5)i3 = 0 Matlab Code to Solve System (note % is used for a comment, note relation to above eqn.) format compact %optional command to print without spaces r1=50; r2=20; r3=20; r4=10; r5=15; a=[r1+r2+r3 -r2 -r3;-r2 r2+r4 -r4;-r3 -r4 r5+r3+r4]; %notice similarity in equations b=[12;-5;0]; %order must match the a matrix x=inv(a)*b i1=x(1) i2=x(2) i3=x(3) ir4=x(3)-x(2) %solving for a branch current Vr4=r4*ir4 %solving for a voltage drop An Example of Plotting a Function in Matlab To plot Matlab Code to Plot Function (note % is used for a comment) t=[0:0.01:2]; %first number is starting point, second is increment, third is ending point y=3*sin(2*pi*t + (pi/2)); plot(t,y) title('my Favorite Sine Function') %These functions can also be done by double clicking axis xlabel('time (sec)') ylabel('amplitude (volts)') axis([0 2-4 4]) %can be used to rescale format is [xmin xmax ymin ymax] Elaine Linde Page 4 Fall 2009

General Note on Multiplying in Matlab Since Matlab was made to process matrices, its first choice is to do this. For example, if, and you type x*y in Matlab, it will give you an error because it is trying to do a matrix multiplication but needs one to be a row vector and one to be a column vector, which they are not. To do an element by element multiplication you need to type x.*y (dot star) to get. Elaine Linde Page 5 Fall 2009

Laboratory 1 Exercises Problem 1 Make files for the two examples above and run them. Hand in the code and plots. Problem 2 Solve the following systems of linear equations using Matlab. If you cannot find a solution, state why a solution cannot be found. Note, the first one is easy and should be used to test the solution method. Your solution should include: 1.) The answer and 2.) the code used to get the solution or 3.) a mathematical explanation of why no answer could be found (think beyond what Matlab tells you). a.) 2x + 3y = 5 b.) 2x + 3y + 4z = 21 c.) 2x + y +z = 3 x +2y = 7 5x + 7y + z = 5 3y + z = 23 (x = -11, y = 9) 3x + y +8z = 15 2x - 2y = -20 d.) 3x + y = 15 e.) 2x + 3y = 17 f.) 2x + 3y + 4z = 26 2x + 20z = 10 5x + 4y = 13 3x + 4y + z = -430 4x + 3y + 5 z = 5 4x + 7y = 3 Problem 3 Plot 3 cycles of. Choose t such that the plot looks smooth. Title the plot and label the axes. Elaine Linde Page 6 Fall 2009

Problem 4 Given this set of data, plot the frequency on the x-axis in log scale and the amplitude on the y-axis in decibels. Amplitude in decibels can be calculated as AdB=20log(A) Frequency 100 1 1000 0.707 2500 0.5 5000 0.26 10000 0.1 25000 0.05 50000 0.005 Amplitude Sample Code freq=[100 1000 2500 5000 10000 25000 50000]; amp=[1 0.707 0.5 0.26 0.1 0.05 0.005]; ampdb=20*log10(amp); semilogx(freq,ampdb) grid title('low Pass Filter') %These functions can also be done by double clicking axis xlabel('freq (Hz)') ylabel('amplitude (db)') Problem 5 In Matlab, type help plot 1.) print this out, 2.) notice the different color and display options, and 3.) notice the also see commands at the bottom these are related functions that you could get help on to find out what they do. Elaine Linde Page 7 Fall 2009