A. Matrix-wise and element-wise operations

Similar documents
Matlab Workshop I. Niloufer Mackey and Lixin Shen

Introduction to MATLAB

Introduction to MATLAB

LAB 1 General MATLAB Information 1

Script started on Thu 25 Aug :00:40 PM CDT

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

General MATLAB Information 1

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Ebooks Chemical Engineering

GRAPH 4.4. Megha K. Raman APRIL 22, 2015

Arithmetic and Logic Blocks

Introduction to MATLAB

Introduction to GNU-Octave

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Introduction to Matlab. Matlab variable types. Matlab variable types. Matlab variable types. Notes. Eugeniy E. Mikhailov. Lecture 02. Notes.

Introduction to Matlab

INTRODUCTION TO MATLAB. Padmanabhan Seshaiyer

National Workshop on LaTeX and MATLAB for Beginners

# Import constants pi2, pip2, pip4 (2*pi, pi/2, pi/4). use Math::Trig ':pi';

Scientific Computing Lecture 1: MATLAB fundamentals

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Chapter 1 MATLAB Preliminaries

Built-in Types of Data

5-2 Verifying Trigonometric Identities

The Official Guide to Easy Graphing. ParaGraph. Ver Congratulations Graphing just got easier.

A General Introduction to Matlab

A very brief Matlab introduction

# Import constants pi2, pip2, pip4 (2*pi, pi/2, pi/4). use Math::Trig ':pi';

MATLAB QUICK START TUTORIAL

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Introduction to MATLAB

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Introduction to Matlab

ARRAY VARIABLES (ROW VECTORS)

MATLAB: a Brief Introduction. by Robert L. Rankin

The value of f(t) at t = 0 is the first element of the vector and is obtained by

A very short introduction to Matlab and Octave

Dr Richard Greenaway

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Some elements for Matlab programming

A Guide to Using Some Basic MATLAB Functions

Section 5.3 Graphs of the Cosecant and Secant Functions 1

Introduction to MATLAB Programming

Math 2250 MATLAB TUTORIAL Fall 2005

The Graphing Calculator

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division

Programming in MATLAB

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

5-2 Verifying Trigonometric Identities

BRUNO WELFERT Arizona State University AND. R. Kent Nagle. University of South Florida. Edward B. Saff. Vanderbilt University. A.

University of Alberta

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

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.

ELEMENTARY MATLAB PROGRAMMING

Introduction to MATLAB for CSE390

Basic stuff -- assignments, arithmetic and functions

Finding, Starting and Using Matlab

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Python. Olmo Zavala R. Python Exercises. Center of Atmospheric Sciences, UNAM. August 24, 2016

MATLAB Functions and Graphics

MATH 5520 Basics of MATLAB

MATH 3511 Basics of MATLAB

Scientific Functions Complex Numbers

Entering the numbers in these two ways creates the same matrix A.

MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

GNU libmatheval manual

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5.

Getting Started with MATLAB

A Brief Introduction to MATLAB

Lecture 1: What is MATLAB?

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

Single row numeric functions

LAB 1: Introduction to MATLAB Summer 2011

MATLAB and Numerical Analysis

x,,, (All real numbers except where there are

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.

Trigonometric Functions of Any Angle

Lab 1 Intro to MATLAB and FreeMat

Lecturer: Keyvan Dehmamy

Primer on MATLAB (This update for v.6 courtesy Prof. Jim Hanson, Bucknell Univ., a former Cornell instructor in 241)

Matlab for Chemists. Theoretical Chemistry Radboud University The Netherlands

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

A BRIEF INTRODUCTION TO MATLAB Fotios Kasolis Introduction

Computational Physics

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

1. GRAPHS OF THE SINE AND COSINE FUNCTIONS

AN INTRODUCTION TO MATLAB

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

( ) = 1 4. (Section 4.6: Graphs of Other Trig Functions) Example. Use the Frame Method to graph one cycle of the graph of

AMS 27L LAB #1 Winter 2009

INTRODUCTION TO MATLAB PROGRAMMING Lec 1.1: MATLAB Basics

How to learn MATLAB? Some predefined variables

FACULTY OF SCIENCE SCHOOL OF MATHEMATICS AND STATISTICS INTRODUCTION TO MATLAB

Using GNU Octave for Numerical Methods

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Part IB Computing Course Tutorial Guide to MATLAB

An Introduction to MATLAB II

Transcription:

USC GSBME MATLAB CLASS Reviewing previous session Second session A. Matrix-wise and element-wise operations A.1. Matrix-wise operations So far we learned how to define variables and how to extract data from them. Here we will learn how to use them. Assume that: x=[1 2;3 4] y=[5 6;7 8] z=x+y Do it yourself! So we will have z= 6 8 10 12 Please note that since it is not possible to add matrices with different sizes (rows and columns), if you try to do so, MATLAB will give you an error. Try to define two matrices and subtract them.

Now, assume that: x=[1 2;3 4] y=[5 6;7 8] z=x*y Note: in MATLAB, asterisk ( * ) represents the multiplying operator, Do it yourself! So we will have z= 19 22 43 50 Which is the result of multiplication of the x and y matrixes. Please note that in matrix multiplication, we can just multiply matrixes with same inner dimensions. Example: A mxn * B nxp Where n is the inner dimension of this multiplication. Try to divide one matrix to another one. 2

A.1. Element-wise operations If we want the operator to operate element-wise (the operator will work on each one of the elements from the first matrix and its corresponding element on the other matrix), we should just put a dot (. ) in front of the operator. Example: C=A.*B C=A.^B Practice the skill you ve learned so far. Assume that: x=[1 2 3 4 5 6 7 8 9 10];y=[1000 100 10 1] try to multiply the third to the sixth elements of the matrix x to the elements of the matrix y with one MATLAB command. The answer should be 3,456. Notes: 3

B. Math functions in MATLAB MATLAB has a diverse library of math functions. Here we will introduce some of the most frequently used ones and show how to use them. Let s start with the sinusoid function. To calculate the sinusoid of an input number, we use the MATLAB function sin(). It is used as output=sin(input). Note that MATLAB will interpret the input as it is in radians. You can also use pi for the π number. Example: y=sin(pi/2) and we will have: y=1 or x=pi/2; y=sin(x) and we will have: y=1 Below is a list of some of the most frequently used math functions in MATLAB. B.1. Sinusoidal functions sin, sinh, asin, asinh, cos, cosh, acos, acosh, tan, tanh, atan, atanh, sec, sech, asec, asech, csc, csch, acsc, acsch, cot, coth, acot, acoth, sinc. 4

B.2. Some other frequently used Math functions exp, fix, log, floor, log10, ceil, log2, round, sqrt, rem, nextpow2, mod, abs, sign, angle, conj, imag, real. Investigate what each of the functions above do (using MATLAB help) and use at least 5 of them in the MATLAB environment. So far we have used the sinusoid function as a one input-one output function. What if we want to enter a string of numbers and have their sinusoids as a string with elements corresponding to the input elements? You can easily create a matrix as an input to the functions above and they will return the output as a matrix with elements corresponding to the elements in the input matrix. Example: ans = sin([pi/2 0; 0 pi/2]) 1 0 Notes: 0 1 5

C. 2D ploting in MATLAB Here we will explain how to plot data using an example. Let s say we want to plot a sinusoid function for one period (as you know, sinusoid function is a periodic function with the periodicity equal to 2π). First we will need a time series. We will use the next command to make a time series starting from 0 and ending in 2π with increments of 0.01. t=0:0.01:2*pi; then we will use the sin() function to calculate the sinusoid of any given time on the t string and name the output as y. y=sin(t); now we can use the plot function in the form of plot( independent variable, dependent variable ). It means we have to type plot(t,y) on the command window. The result will be shown in a new figure box. You should see a result similar to the one shown below: 6

In fact, you can just use plot function with only one argument. In this case, your x axis (independent variable) will be the sample number. plot(y) (You can also use the stem function instead of plot to illustrate your data in a discrete manner) Try to plot the following function for the t=0:0.01:2 interval. y = 5e 3t Notes: 7

D. Polynomials in MATLAB In MATLAB, any polynomial will be described as a string of numbers (let s call it C) which represents the coefficients as described below: C=[C m C m-1 C 1 C 0 ]; Respresents: C m X m + C m-1 X m-1 + + C 1 X + C 0 To find the roots of a polynomial: R=roots(C) To find the coefficients for a known set of roots: C=poly(R) To compute the value of the polynomial with coefficients C at the input equals to x: y=polyval(c,x) To differentiate from the polynomial with coefficients C: dc=polyder(c) To integrate from the polynomial with coefficients C: IC=polyint(C) Please note that MATLAB will set the integration constant to zero. To find the coefficients that its polynomial fits best to a set of data: C=polyfit(x,y,n) 8

Where x is the input (independent variable), y is the output (dependent variable which we want to fit our polynomial to) and n is the polynomial order. Try to choose at least two of the functions above (except polyfit) and use them in MATLAB Try to find the set of coefficients for a polynomial of order 5 that fits best the input-output that described below: Input: x=0:0.05:2*pi; Output: y=sin(x); After you find the coefficients, try to plot those using polyval and plot functions to see how good it is fitted on your data. - Tip: You can use hold on command after your first plot to let the other plots to be plotted on the same figure. Notes: 9