Numerical Methods Lecture 1

Size: px
Start display at page:

Download "Numerical Methods Lecture 1"

Transcription

1 Numerical Methods Lecture 1 Basics of MATLAB by Pavel Ludvík

2 The recommended textbook: Numerical Methods Lecture 1 by Pavel Ludvík 2 / 30

3 The recommended textbook: Title: Numerical methods with worked examples: Matlab edition Authors: WOODFORD, Chris a Chris PHILLIPS Publisher: New York: Springer, c2012 Numerical Methods Lecture 1 by Pavel Ludvík 2 / 30

4 Basics of MATLAB Numerical Methods Lecture 1 by Pavel Ludvík 3 / 30

5 MATLAB = MATrix LABoratory MATLAB was devised by Cleve Moler in the late 1970 s to make numerical computing easier for students at the University of New Mexico. Many of the obstacles to using a computer for mathematics were removed. In a MATLAB program variables, whether real or complex numbers, vectors or matrices may be named and used as and when required without prior notification or declaration and may be manipulated according to the rules of mathematics. MATLAB spread to other Universities and in 1984 Cleve went into partnership with a colleague to set up a company called Mathworks to market MATLAB. Mathworks is now a multi-national corporation specialising in technical computing software. MATLAB and products built on MATLAB are used all over the world by innovative technology companies, government research labs, financial institutions, and more than 3,500 universities. Numerical Methods Lecture 1 by Pavel Ludvík 4 / 30

6 Windows in MATLAB and Their Function Numerical Methods Lecture 1 by Pavel Ludvík 5 / 30

7 Creating Variables and Using Basic Arithmetic 1. To create a single variable just use it on the left hand side of an equal sign. Enter the name of the variable to see its current value. Numerical Methods Lecture 1 by Pavel Ludvík 6 / 30

8 Creating Variables and Using Basic Arithmetic Exercise Enter the following commands on separate lines. 1. r=4 2. ab1= r 4. A=r 2 5. sol=ab1*(1+1/r) 6. ab1=sol (1/2) 7. CV2=10/3 8. x=1.5e-2 Numerical Methods Lecture 1 by Pavel Ludvík 6 / 30

9 Creating Variables and Using Basic Arithmetic Exercise Enter the following commands on separate lines. 1. r=4 2. ab1= r 4. A=r 2 5. sol=ab1*(1+1/r) 6. ab1=sol (1/2) 7. CV2=10/3 8. x=1.5e-2 Try to write several command on the same line separating them by a comma or a semi-colon. What is the difference? Numerical Methods Lecture 1 by Pavel Ludvík 6 / 30

10 Standard Functions MATLAB provides a large number of commonly used functions including abs, sqrt, exp, log and sin, cos and tan and inverses asin, acos, atan. Numerical Methods Lecture 1 by Pavel Ludvík 7 / 30

11 Standard Functions MATLAB provides a large number of commonly used functions including abs, sqrt, exp, log and sin, cos and tan and inverses asin, acos, atan. Exercise Use MATLAB to calculate the following. 1. x=sqrt(2) 2. A=sin(1.5) 3. a=sqrt(x 2+A 2) 4. y=exp(1/x) Numerical Methods Lecture 1 by Pavel Ludvík 7 / 30

12 Standard Functions MATLAB provides a large number of commonly used functions including abs, sqrt, exp, log and sin, cos and tan and inverses asin, acos, atan. Exercise Use MATLAB to calculate the following. 1. x=sqrt(2) 2. A=sin(1.5) 3. a=sqrt(x 2+A 2) 4. y=exp(1/x) Look up the entry Elementary Math in MATLAB s help. Numerical Methods Lecture 1 by Pavel Ludvík 7 / 30

13 Standard Functions Exercise 1. Find the longest side of a right angled triangle whose other sides have lengths 12 and 5. Use the Pythagoras Theorem. 2. Find the roots of the quadratic function 3x 2 13x + 4 using the standard formula. Exercise Try to find the values of constants π and e in MATLAB. Numerical Methods Lecture 1 by Pavel Ludvík 8 / 30

14 Vectors and Matrices The matrix is created by A = A = [2 3-1; 4 8-3; ]. Numerical Methods Lecture 1 by Pavel Ludvík 9 / 30

15 Vectors and Matrices The matrix is created by Exercise A = A = [2 3-1; 4 8-3; ]. 1. Create the row vector x = (4, 10, 1, 0). 2. Create the column vector y = ( 5.3, 2, 0.9, 1). 3. Create the matrix B = Numerical Methods Lecture 1 by Pavel Ludvík 9 / 30

16 Vectors and Matrices A = 4 8 3, B = Find out what happens if you type A(1,2), A(:,1) and A(3,:). Figure out what mathematical operations can performed with matrices A and B. Numerical Methods Lecture 1 by Pavel Ludvík 10 / 30

17 Vectors and Matrices Exercise Write a linear system 3x 1 + 5x 2 + 7x 3 = 25, x 1 4x 2 + 2x 3 = 10, 4x 1 x 2 3x 3 = 1 in a matrix form as Ax = b and solve it using MATLAB (realize that a notion of a inverse matrix can be employed). Numerical Methods Lecture 1 by Pavel Ludvík 11 / 30

18 Vectors and Matrices Exercise Write a linear system 3x 1 + 5x 2 + 7x 3 = 25, x 1 4x 2 + 2x 3 = 10, 4x 1 x 2 3x 3 = 1 in a matrix form as Ax = b and solve it using MATLAB (realize that a notion of a inverse matrix can be employed). Use the command x=a\b and compare it with the previous result. Numerical Methods Lecture 1 by Pavel Ludvík 11 / 30

19 Defining Mathematical Functions In most situations, we will define the mathematical functions in the following way: Consider the functions f (x) = x 2 sin(2x), g(x, y) = x 2 + y 2 cos 2 (xy). You can define them by f=@(x)x^2-sin(2*x) g=@(x,y)x^2+y^2-cos(x*y)^2 Numerical Methods Lecture 1 by Pavel Ludvík 12 / 30

20 Plotting Command plot(x,y) x=[ ] y=[ ] plot(x,y) grid on Command fplot(f,[a,b]) f=@(x) x^2-2*x g=@(x) sin(3*x) fplot(f,[-1 5]) hold on, grid on fplot(g,[-1 5], r ) Look up plot and fplot in help of MATLAB. Numerical Methods Lecture 1 by Pavel Ludvík 13 / 30

21 Plotting Data and Functions Exercises 1. Plot the functions y = x and y = sin(x) and y = cos(x) over the range [0, 2π] on the same graph but using different colours. 2. Plot the three dimensional surface defined by z = x 2 y 2 across the x y ranges [ 2, 2] on both axes. Numerical Methods Lecture 1 by Pavel Ludvík 14 / 30

22 Solution of Exercise 2 % establish a grid of points equally spaced at intervals of 0.1 across the range [x, y] = meshgrid(-2 : 0.1 : 2, -2 : 0.1 : 2); % establish z-values using element by element multiplication z = x.*x - y.*y % plot the surface surf(x, y, z); colorbar % show the colour scale. Numerical Methods Lecture 1 by Pavel Ludvík 15 / 30

23 M-Files On the whole entering MATLAB commands and statements line by line is too error prone for anything but very short, transitory programs. Programs under development and programs which are going to be used repeatedly are better stored as a sequence of commands in a file. Such files are called M-files. Numerical Methods Lecture 1 by Pavel Ludvík 16 / 30

24 M-Files On the whole entering MATLAB commands and statements line by line is too error prone for anything but very short, transitory programs. Programs under development and programs which are going to be used repeatedly are better stored as a sequence of commands in a file. Such files are called M-files. Exercise 1. Use the file menu to create an M-file. Enter a sequence of commands. Save the file using a name of your choice. Execute the newly created M-file. Edit the file if necessary to obtain successful execution, then close the file. 2. Re-open the M-file, make changes to the program and reexecute. Numerical Methods Lecture 1 by Pavel Ludvík 16 / 30

25 The colon Notation and the for Loop How the colon works k:n is equivalent to k, 2, 3, 4,..., n. (incrementing by 1) k:m:n is equivalent to k, k + m, k + 2m, k + 3m,..., n. (incrementing by m) We use the for construct to sum the first 10 integers (1, 2,... 10): addnumbers = 0; % initial total for i = 1 : 10; addnumbers = addnumbers + i; % running total end Numerical Methods Lecture 1 by Pavel Ludvík 17 / 30

26 The colon Notation and the for Loop Exercises 1. By making a small change to the program above, use MATLAB to find the sum of the even numbers 2, 4,..., The following series may be used to calculate an approximation to 2 x n+1 = x n x n, n = 1, 2,..., x 1 = 1. Calculate x 1, x 2,..., x 7 and show convergence to 2. Numerical Methods Lecture 1 by Pavel Ludvík 18 / 30

27 The colon Notation and the for Loop The following code would be sufficient to solve problem no. 2: x(1) = 1 % first approximation for n = 1 : 6 x(n+1) = x(n)/2 + 1/x(n) % successive approximations end Exercise Devise an alternative, more economical (with respect to the computer memory) version which does not save intermediate results but simply displays and then overwrites the current estimate of 2 by the next estimate. Numerical Methods Lecture 1 by Pavel Ludvík 19 / 30

28 The colon Notation and the for Loop Exercises The Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13,... (each number is the sum of the two preceding numbers) relate to several natural phenomena. Use a for loop to print the first 20 Fibonacci numbers. Numerical Methods Lecture 1 by Pavel Ludvík 20 / 30

29 The if Construct In addition to the loop structure program flow may be controlled using if, else and elseif. Trace the basic if construct in the help of MATLAB. Numerical Methods Lecture 1 by Pavel Ludvík 21 / 30

30 The if Construct In addition to the loop structure program flow may be controlled using if, else and elseif. Trace the basic if construct in the help of MATLAB. Question What kind of logical conjunctions do you know? Numerical Methods Lecture 1 by Pavel Ludvík 21 / 30

31 Enter the code in a MATLAB program to verify the outcome. x = 2; y = 1; if x > 2; y = x; end; a = 1; b = 2; if a == 1; b = a + 1; end; u = 1; v = 2; w = -2; if (u ~= 0 & u < abs(w) ) u < 0; u = u + w; else u = u - w; end; Numerical Methods Lecture 1 by Pavel Ludvík 22 / 30

32 The if Construct Exercise In using the formula for the solution of a quadratic equation the discriminant b 2 4ac may be positive (indicating two real roots), zero (a double root) or negative (complex roots). Write MATLAB code to set a variable roots to 2, 1 or 0 depending on the value of the discriminant. Test the program using various values of a, b and c. Numerical Methods Lecture 1 by Pavel Ludvík 23 / 30

33 The if Construct Exercise In using the formula for the solution of a quadratic equation the discriminant b 2 4ac may be positive (indicating two real roots), zero (a double root) or negative (complex roots). Write MATLAB code to set a variable roots to 2, 1 or 0 depending on the value of the discriminant. Test the program using various values of a, b and c. Exercise Given a vector (or matrix) of dimension (m, n) use a for loop within a for loop to count the number of non-zero elements. Test your code on simple examples. Numerical Methods Lecture 1 by Pavel Ludvík 23 / 30

34 The while Loop The while loop repeats a sequence of instructions until a specified condition is met. It is used as an alternative to the for loop in cases where the number of required repeats is not known in advance. Trace the basic while construct in the help of MATLAB. Numerical Methods Lecture 1 by Pavel Ludvík 24 / 30

35 The while Loop The while loop repeats a sequence of instructions until a specified condition is met. It is used as an alternative to the for loop in cases where the number of required repeats is not known in advance. Trace the basic while construct in the help of MATLAB. Exercise Create a vector of numbers which contains one or more zeros. Construct a while loop to find the sum of the numbers up to the first zero. Numerical Methods Lecture 1 by Pavel Ludvík 24 / 30

36 Simple Screen Output and Keyboard Input Screen Output As an alternative to entering the name of a variable the function disp may be used to output a value or a string. The standard forms are disp(x) and disp( s ) where x is a variable and s is a string of alphanumeric and other characters. Numerical Methods Lecture 1 by Pavel Ludvík 25 / 30

37 Simple Screen Output and Keyboard Input Screen Output As an alternative to entering the name of a variable the function disp may be used to output a value or a string. The standard forms are disp(x) and disp( s ) where x is a variable and s is a string of alphanumeric and other characters. Keyboard Input The function input may be used to request user input. The standard form is x = input( request ). The user sees the character string request on the screen and enters number(s) from the keyboard to be allocated to the program variable x. Numerical Methods Lecture 1 by Pavel Ludvík 25 / 30

38 Simple Screen Output and Keyboard Input As part of an interactive program, use the following code to obtain the value of m and echo the input to the screen. The program asks for confirmation (Y or N) that the number is correct and if necessary repeats the original request. m = input( Enter the number of data values \n ); reply = input( Is that correct, answer Y or N\n, s ); while ~strcmp(reply, Y ) input( Enter the number of data values\n ); reply = input( Is that correct, answer Y or N\n, s ); end; disp( Thank you ); Numerical Methods Lecture 1 by Pavel Ludvík 26 / 30

39 Simple Screen Output and Keyboard Input Exercise Write a program to request a password from the user. Compare the reply with a stored string. If necessary repeat the request at most twice until there is an agreement. Numerical Methods Lecture 1 by Pavel Ludvík 27 / 30

40 User Defined Functions You can define your own function stored i an M-file. The function heading has the form: function [out1, out2,... ] = functionname (in1, in2,... ) and M-file has to be saved under the same name as is a name of the function. Example Sum of the series 1 + x + x x n : function [result] = sumgp(x, n) if x == 1; result = n+1 % Check for the exceptional case. else result = (x^(n+1) - 1)/(x - 1) end Numerical Methods Lecture 1 by Pavel Ludvík 28 / 30

41 User Defined Functions Exercise Write a function MaxElement to find the largest absolute value of all elements of an array or vector. Test the function on simple examples. Numerical Methods Lecture 1 by Pavel Ludvík 29 / 30

42 User Defined Functions Exercise Write a function MaxElement to find the largest absolute value of all elements of an array or vector. Test the function on simple examples. Solution (One of Many): function [result] = MaxElement(v) result = 0; for i = 1 : length(v) if abs(v(i)) > result; result = abs(v(i)); end end Numerical Methods Lecture 1 by Pavel Ludvík 30 / 30

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name: 1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write

More information

Introduction to MATLAB Programming

Introduction to MATLAB Programming Introduction to MATLAB Programming Arun A. Balakrishnan Asst. Professor Dept. of AE&I, RSET Overview 1 Overview 2 Introduction 3 Getting Started 4 Basics of Programming Overview 1 Overview 2 Introduction

More information

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

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB? Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science

More information

A very brief Matlab introduction

A very brief Matlab introduction A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER BENC 2113 DENC ECADD 2532 ECADD LAB SESSION 6/7 LAB

More information

LAB 1 General MATLAB Information 1

LAB 1 General MATLAB Information 1 LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by

More information

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

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3. MATLAB Introduction Accessing Matlab... Matlab Interface... The Basics... 2 Variable Definition and Statement Suppression... 2 Keyboard Shortcuts... More Common Functions... 4 Vectors and Matrices... 4

More information

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

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano MATLAB Lesson I Chiara Lelli Politecnico di Milano October 2, 2012 MATLAB MATLAB (MATrix LABoratory) is an interactive software system for: scientific computing statistical analysis vector and matrix computations

More information

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

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

EE 301 Signals & Systems I MATLAB Tutorial with Questions

EE 301 Signals & Systems I MATLAB Tutorial with Questions EE 301 Signals & Systems I MATLAB Tutorial with Questions Under the content of the course EE-301, this semester, some MATLAB questions will be assigned in addition to the usual theoretical questions. This

More information

Math 2250 MATLAB TUTORIAL Fall 2005

Math 2250 MATLAB TUTORIAL Fall 2005 Math 2250 MATLAB TUTORIAL Fall 2005 Math Computer Lab The Mathematics Computer Lab is located in the T. Benny Rushing Mathematics Center (located underneath the plaza connecting JWB and LCB) room 155C.

More information

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs in MATLAB NOTE: For your

More information

MATH 3511 Basics of MATLAB

MATH 3511 Basics of MATLAB MATH 3511 Basics of MATLAB Dmitriy Leykekhman Spring 2012 Topics Sources. Entering Matrices. Basic Operations with Matrices. Build in Matrices. Build in Scalar and Matrix Functions. if, while, for m-files

More information

MEI GeoGebra Tasks for A2 Core

MEI GeoGebra Tasks for A2 Core Task 1: Functions The Modulus Function 1. Plot the graph of y = x : use y = x or y = abs(x) 2. Plot the graph of y = ax+b : use y = ax + b or y = abs(ax+b) If prompted click Create Sliders. What combination

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Kristian Sandberg Department of Applied Mathematics University of Colorado Goal The goal with this worksheet is to give a brief introduction to the mathematical software Matlab.

More information

SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK

SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK Mathematical Statistics SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK 1 Preparation This computer exercise is a bit different from the other two, and has some overlap with computer

More information

Computer Programming in MATLAB

Computer Programming in MATLAB Computer Programming in MATLAB Prof. Dr. İrfan KAYMAZ Atatürk University Engineering Faculty Department of Mechanical Engineering What is a computer??? Computer is a device that computes, especially a

More information

ARRAY VARIABLES (ROW VECTORS)

ARRAY VARIABLES (ROW VECTORS) 11 ARRAY VARIABLES (ROW VECTORS) % Variables in addition to being singular valued can be set up as AN ARRAY of numbers. If we have an array variable as a row of numbers we call it a ROW VECTOR. You can

More information

Finding, Starting and Using Matlab

Finding, Starting and Using Matlab Variables and Arrays Finding, Starting and Using Matlab CSC March 6 &, 9 Array: A collection of data values organized into rows and columns, and known by a single name. arr(,) Row Row Row Row 4 Col Col

More information

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c.

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c. MATLAB BASICS Starting Matlab < PC: Desktop icon or Start menu item < UNIX: Enter matlab at operating system prompt < Others: Might need to execute from a menu somewhere Entering Matlab commands < Matlab

More information

1 Introduction to Matlab

1 Introduction to Matlab 1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing

More information

MATH 5520 Basics of MATLAB

MATH 5520 Basics of MATLAB MATH 5520 Basics of MATLAB Dmitriy Leykekhman Spring 2011 Topics Sources. Entering Matrices. Basic Operations with Matrices. Build in Matrices. Build in Scalar and Matrix Functions. if, while, for m-files

More information

Matlab and Octave: Quick Introduction and Examples 1 Basics

Matlab and Octave: Quick Introduction and Examples 1 Basics Matlab and Octave: Quick Introduction and Examples 1 Basics 1.1 Syntax and m-files There is a shell where commands can be written in. All commands must either be built-in commands, functions, names of

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 3 Creating, Organising & Processing Data Dr Richard Greenaway 3 Creating, Organising & Processing Data In this Workshop the matrix type is introduced

More information

MatLab Just a beginning

MatLab Just a beginning MatLab Just a beginning P.Kanungo Dept. of E & TC, C.V. Raman College of Engineering, Bhubaneswar Introduction MATLAB is a high-performance language for technical computing. MATLAB is an acronym for MATrix

More information

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

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms: Appendix A Basic MATLAB Tutorial Extracted from: http://www1.gantep.edu.tr/ bingul/ep375 http://www.mathworks.com/products/matlab A.1 Introduction This is a basic tutorial for the MATLAB program which

More information

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS 1 6 3 Matlab 3.1 Fundamentals Matlab. The name Matlab stands for matrix laboratory. Main principle. Matlab works with rectangular

More information

Introduction to Matlab

Introduction to Matlab What is Matlab? Introduction to Matlab Matlab is software written by a company called The Mathworks (mathworks.com), and was first created in 1984 to be a nice front end to the numerical routines created

More information

PART 1 PROGRAMMING WITH MATHLAB

PART 1 PROGRAMMING WITH MATHLAB PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Basics MATLAB is a high-level interpreted language, and uses a read-evaluate-print loop: it reads your command, evaluates it, then prints the answer. This means it works a lot like

More information

George Mason University ECE 201: Introduction to Signal Analysis Spring 2017

George Mason University ECE 201: Introduction to Signal Analysis Spring 2017 Assigned: January 27, 2017 Due Date: Week of February 6, 2017 George Mason University ECE 201: Introduction to Signal Analysis Spring 2017 Laboratory Project #1 Due Date Your lab report must be submitted

More information

Lab 1 Intro to MATLAB and FreeMat

Lab 1 Intro to MATLAB and FreeMat Lab 1 Intro to MATLAB and FreeMat Objectives concepts 1. Variables, vectors, and arrays 2. Plotting data 3. Script files skills 1. Use MATLAB to solve homework problems 2. Plot lab data and mathematical

More information

Introduction to MATLAB Practical 1

Introduction to MATLAB Practical 1 Introduction to MATLAB Practical 1 Daniel Carrera November 2016 1 Introduction I believe that the best way to learn Matlab is hands on, and I tried to design this practical that way. I assume no prior

More information

Introduction to Matlab

Introduction to Matlab What is Matlab? Introduction to Matlab Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

Laboratory 1 Introduction to MATLAB for Signals and Systems

Laboratory 1 Introduction to MATLAB for Signals and Systems Laboratory 1 Introduction to MATLAB for Signals and Systems INTRODUCTION to MATLAB MATLAB is a powerful computing environment for numeric computation and visualization. MATLAB is designed for ease of use

More information

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial STAT/MATH 395 A - PROBABILITY II UW Winter Quarter 2016 Néhémy Lim Matlab Tutorial 1 Introduction Matlab (standing for matrix laboratory) is a high-level programming language and interactive environment

More information

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands How to Use MATLAB What is MATLAB MATLAB is an interactive package for numerical analysis, matrix computation, control system design and linear system analysis and design. On the server bass, MATLAB version

More information

AMS 27L LAB #2 Winter 2009

AMS 27L LAB #2 Winter 2009 AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles

More information

McTutorial: A MATLAB Tutorial

McTutorial: A MATLAB Tutorial McGill University School of Computer Science Sable Research Group McTutorial: A MATLAB Tutorial Lei Lopez Last updated: August 2014 w w w. s a b l e. m c g i l l. c a Contents 1 MATLAB BASICS 3 1.1 MATLAB

More information

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control

More information

A Guide to Using Some Basic MATLAB Functions

A Guide to Using Some Basic MATLAB Functions A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available

More information

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs

More information

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

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful

More information

3+2 3*2 3/2 3^2 3**2 In matlab, use ^ or ** for exponentiation. In fortran, use only ** not ^ VARIABLES LECTURE 1: ARITHMETIC AND FUNCTIONS

3+2 3*2 3/2 3^2 3**2 In matlab, use ^ or ** for exponentiation. In fortran, use only ** not ^ VARIABLES LECTURE 1: ARITHMETIC AND FUNCTIONS LECTURE 1: ARITHMETIC AND FUNCTIONS MATH 190 WEBSITE: www.math.hawaii.edu/ gautier/190.html PREREQUISITE: You must have taken or be taking Calculus I concurrently. If not taken here, specify the college

More information

1. Register an account on: using your Oxford address

1. Register an account on:   using your Oxford  address 1P10a MATLAB 1.1 Introduction MATLAB stands for Matrix Laboratories. It is a tool that provides a graphical interface for numerical and symbolic computation along with a number of data analysis, simulation

More information

Lecture 1 arithmetic and functions

Lecture 1 arithmetic and functions Lecture 1 arithmetic and functions MATH 190 WEBSITE: www.math.hawaii.edu/190 Open MATH 190 in a web browser. Read and accept the Terms of Acceptable Lab Use. Open Lecture 1. PREREQUISITE: You must have

More information

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,

More information

Exercises C-Programming

Exercises C-Programming Exercises C-Programming Claude Fuhrer (claude.fuhrer@bfh.ch) 0 November 016 Contents 1 Serie 1 1 Min function.................................. Triangle surface 1............................... 3 Triangle

More information

Summer 2009 REU: Introduction to Matlab

Summer 2009 REU: Introduction to Matlab Summer 2009 REU: Introduction to Matlab Moysey Brio & Paul Dostert June 29, 2009 1 / 19 Using Matlab for the First Time Click on Matlab icon (Windows) or type >> matlab & in the terminal in Linux. Many

More information

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

More information

MATLAB. Devon Cormack and James Staley

MATLAB. Devon Cormack and James Staley MATLAB Devon Cormack and James Staley MATrix LABoratory Originally developed in 1970s as a FORTRAN wrapper, later rewritten in C Designed for the purpose of high-level numerical computation, visualization,

More information

What is MATLAB and howtostart it up?

What is MATLAB and howtostart it up? MAT rix LABoratory What is MATLAB and howtostart it up? Object-oriented high-level interactive software package for scientific and engineering numerical computations Enables easy manipulation of matrix

More information

2nd Year Computational Physics Week 1 (experienced): Series, sequences & matrices

2nd Year Computational Physics Week 1 (experienced): Series, sequences & matrices 2nd Year Computational Physics Week 1 (experienced): Series, sequences & matrices 1 Last compiled September 28, 2017 2 Contents 1 Introduction 5 2 Prelab Questions 6 3 Quick check of your skills 9 3.1

More information

Floating-point representation

Floating-point representation Lecture 3-4: Floating-point representation and arithmetic Floating-point representation The notion of real numbers in mathematics is convenient for hand computations and formula manipulations. However,

More information

Digital Image Analysis and Processing CPE

Digital Image Analysis and Processing CPE Digital Image Analysis and Processing CPE 0907544 Matlab Tutorial Dr. Iyad Jafar Outline Matlab Environment Matlab as Calculator Common Mathematical Functions Defining Vectors and Arrays Addressing Vectors

More information

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50 MATLAB Premier Middle East Technical University Department of Mechanical Engineering ME 304 1/50 Outline Introduction Basic Features of MATLAB Prompt Level and Basic Arithmetic Operations Scalars, Vectors,

More information

Introduction to MATLAB LAB 1

Introduction to MATLAB LAB 1 Introduction to MATLAB LAB 1 1 Basics of MATLAB MATrix LABoratory A super-powerful graphing calculator Matrix based numeric computation Embedded Functions Also a programming language User defined functions

More information

Guide to Planning Functions and Applications, Grade 11, University/College Preparation (MCF3M)

Guide to Planning Functions and Applications, Grade 11, University/College Preparation (MCF3M) Guide to Planning Functions and Applications, Grade 11, University/College Preparation (MCF3M) 006 007 Targeted Implementation and Planning Supports for Revised Mathematics This is intended to provide

More information

18.02 Multivariable Calculus Fall 2007

18.02 Multivariable Calculus Fall 2007 MIT OpenCourseWare http://ocw.mit.edu 18.02 Multivariable Calculus Fall 2007 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 18.02 Problem Set 4 Due Thursday

More information

Introduction to Mathematical Programming

Introduction to Mathematical Programming Introduction to Mathematical Programming Ming Zhong Lecture 3 September 5, 2018 Ming Zhong (JHU) AMS Fall 2018 1 / 14 Programming with MATLAB Table of Contents 1 Programming with MATLAB 2 Logic, Loops

More information

ELEMENTARY MATLAB PROGRAMMING

ELEMENTARY MATLAB PROGRAMMING 1 ELEMENTARY MATLAB PROGRAMMING (Version R2013a used here so some differences may be encountered) COPYRIGHT Irving K. Robbins 1992, 1998, 2014, 2015 All rights reserved INTRODUCTION % It is assumed the

More information

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

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services MATLAB INTRODUCTION Risk analysis lab 2018 2018. szeptember 10., Budapest Ceffer Attila PhD student BUTE Department Of Networked Systems and Services ceffer@hit.bme.hu Előadó képe MATLAB Introduction 2

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Enrique Muñoz Ballester Dipartimento di Informatica via Bramante 65, 26013 Crema (CR), Italy enrique.munoz@unimi.it Contact Email: enrique.munoz@unimi.it Office: Room BT-43 Industrial,

More information

MATLAB QUICK START TUTORIAL

MATLAB QUICK START TUTORIAL MATLAB QUICK START TUTORIAL This tutorial is a brief introduction to MATLAB which is considered one of the most powerful languages of technical computing. In the following sections, the basic knowledge

More information

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

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below. What is MATLAB? MATLAB (short for MATrix LABoratory) is a language for technical computing, developed by The Mathworks, Inc. (A matrix is a rectangular array or table of usually numerical values.) MATLAB

More information

Some elements for Matlab programming

Some elements for Matlab programming Some elements for Matlab programming Nathalie Thomas 2018 2019 Matlab, which stands for the abbreviation of MATrix LABoratory, is one of the most popular language for scientic computation. The classical

More information

LECTURE 0: Introduction and Background

LECTURE 0: Introduction and Background 1 LECTURE 0: Introduction and Background September 10, 2012 1 Computational science The role of computational science has become increasingly significant during the last few decades. It has become the

More information

General MATLAB Information 1

General MATLAB Information 1 Introduction to MATLAB General MATLAB Information 1 Once you initiate the MATLAB software, you will see the MATLAB logo appear and then the MATLAB prompt >>. The prompt >> indicates that MATLAB is awaiting

More information

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations MATLAB Tutorial The following tutorial has been compiled from several resources including the online Help menu of MATLAB. It contains a list of commands that will be directly helpful for understanding

More information

PreCalculus Summer Assignment

PreCalculus Summer Assignment PreCalculus Summer Assignment Welcome to PreCalculus! We are excited for a fabulous year. Your summer assignment is available digitally on the Lyman website. You are expected to print your own copy. Expectations:

More information

Prerequisites for Math 130

Prerequisites for Math 130 Prerequisites for Math 0 The material below represents only some of the basic material with which you should be familiar We will not be reviewing this material You may wish to consult Appendix A in your

More information

f( x ), or a solution to the equation f( x) 0. You are already familiar with ways of solving

f( x ), or a solution to the equation f( x) 0. You are already familiar with ways of solving The Bisection Method and Newton s Method. If f( x ) a function, then a number r for which f( r) 0 is called a zero or a root of the function f( x ), or a solution to the equation f( x) 0. You are already

More information

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

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1 Chapter 2 (Part 2) MATLAB Basics dr.dcd.h CS 101 /SJC 5th Edition 1 Display Format In the command window, integers are always displayed as integers Characters are always displayed as strings Other values

More information

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

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences Introductory remarks MATLAB: a product of mathworks www.mathworks.com MATrix LABoratory What can we do (in or ) with MATLAB o Use like

More information

MATLAB Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos, sin,

More information

University of Alberta

University of Alberta A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.

More information

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MatLab. Introduction to MatLab K. Craig 1 Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations

More information

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) 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 CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

A General Introduction to Matlab

A General Introduction to Matlab Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti

More information

Eng Marine Production Management. Introduction to Matlab

Eng Marine Production Management. Introduction to Matlab Eng. 4061 Marine Production Management Introduction to Matlab What is Matlab? Matlab is a commercial "Matrix Laboratory" package which operates as an interactive programming environment. Matlab is available

More information

An Introductory Tutorial on Matlab

An Introductory Tutorial on Matlab 1. Starting Matlab An Introductory Tutorial on Matlab We follow the default layout of Matlab. The Command Window is used to enter MATLAB functions at the command line prompt >>. The Command History Window

More information

Introduction to Matlab

Introduction to Matlab Technische Universität München WT 21/11 Institut für Informatik Prof Dr H-J Bungartz Dipl-Tech Math S Schraufstetter Benjamin Peherstorfer, MSc October 22nd, 21 Introduction to Matlab Engineering Informatics

More information

INTRODUCTION TO MATLAB PROGRAMMING Lec 1.1: MATLAB Basics

INTRODUCTION TO MATLAB PROGRAMMING Lec 1.1: MATLAB Basics INTRODUCTION TO MATLAB PROGRAMMING Lec 1.1: MATLAB Basics Dr. Niket Kaisare Department of Chemical Engineering IIT Madras NPTEL Course: MATLAB Programming for Numerical Computations Week-1 About this Module

More information

Introduction to GNU-Octave

Introduction to GNU-Octave Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016

More information

Lecture 1: What is MATLAB?

Lecture 1: What is MATLAB? Lecture 1: What is MATLAB? Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1. MATLAB MATLAB (MATrix LABoratory) is a numerical

More information

What is log a a equal to?

What is log a a equal to? How would you differentiate a function like y = sin ax? What is log a a equal to? How do you prove three 3-D points are collinear? What is the general equation of a straight line passing through (a,b)

More information

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

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu 0. What is MATLAB? 1 MATLAB stands for matrix laboratory and is one of the most popular software for numerical computation. MATLAB s basic

More information

AN INTRODUCTION TO MATLAB

AN INTRODUCTION TO MATLAB AN INTRODUCTION TO MATLAB 1 Introduction MATLAB is a powerful mathematical tool used for a number of engineering applications such as communication engineering, digital signal processing, control engineering,

More information

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE

More information

Computational Mathematics/Information Technology. Worksheet 2 Iteration and Excel

Computational Mathematics/Information Technology. Worksheet 2 Iteration and Excel Computational Mathematics/Information Technology Worksheet 2 Iteration and Excel This sheet uses Excel and the method of iteration to solve the problem f(x) = 0. It introduces user functions and self referencing

More information

EGR 111 Loops. This lab is an introduction to loops, which allow MATLAB to repeat commands a certain number of times.

EGR 111 Loops. This lab is an introduction to loops, which allow MATLAB to repeat commands a certain number of times. EGR 111 Loops This lab is an introduction to loops, which allow MATLAB to repeat commands a certain number of times. New MATLAB commands: for, while,, length 1. The For Loop Suppose we want print a statement

More information

MBI REU Matlab Tutorial

MBI REU Matlab Tutorial MBI REU Matlab Tutorial Lecturer: Reginald L. McGee II, Ph.D. June 8, 2017 MATLAB MATrix LABoratory MATLAB is a tool for numerical computation and visualization which allows Real & Complex Arithmetics

More information

MATLAB is a multi-paradigm numerical computing environment fourth-generation programming language. A proprietary programming language developed by

MATLAB is a multi-paradigm numerical computing environment fourth-generation programming language. A proprietary programming language developed by 1 MATLAB is a multi-paradigm numerical computing environment fourth-generation programming language. A proprietary programming language developed by MathWorks In 2004, MATLAB had around one million users

More information

MATLAB Guide to Fibonacci Numbers

MATLAB Guide to Fibonacci Numbers MATLAB Guide to Fibonacci Numbers and the Golden Ratio A Simplified Approach Peter I. Kattan Petra Books www.petrabooks.com Peter I. Kattan, PhD Correspondence about this book may be sent to the author

More information

50 Basic Examples for Matlab

50 Basic Examples for Matlab 50 Basic Examples for Matlab v. 2012.3 by HP Huang (typos corrected, 10/2/2012) Supplementary material for MAE384, 502, 578, 598 1 Ex. 1 Write your first Matlab program a = 3; b = 5; c = a+b 8 Part 1.

More information