PHS3XXX Computational Physics

Size: px
Start display at page:

Download "PHS3XXX Computational Physics"

Transcription

1 1 PHS3XXX Computational Physics Lecturer: Mike Wheatland Lecture and lab schedule (SNH Learning Studio 4003) 1 There are 10 weeks of lectures and labs Lectures: Mon 9am Labs: Wed 1pm-3pm The labs start in week 1 First lab: this Wednesday Online pre-lab quizzes to be completed each week in elearning consisting of 5 multiple-choice Qs 1 For more details see the outline.

2 2 Topics covered 2 Week 1: Review of MATLAB, numerical error Ordinary Differential Equations (ODEs) Week 2: Euler and midpoint methods projectile motion Week 3: Verlet methods planetary motion Week 4: Runge-Kutta motion of a pendulum Week 5: Relaxation method steady-state quantum physics Partial Differential Equations (PDEs) Week 6: FTCS heat diffusion Week 7: Lax, Lax-Wendroff propagation of waves Week 8: Nonlinear Lax-Wendroff traffic flow Week 9: Jacobi relaxation etc. electrostatics Week 10: Crank-Nicolson time-dependent quantum physics 2 For more details see the outline.

3 3 Computational Physics Week 1 Overview of MATLAB Types of numerical error floating point errors representation of numbers truncation error numerical method Review of MATLAB (assumed knowledge) elements of the language array/matrix features a script with examples (matlab_examples.m) an example function (dice.m) some tips on debugging a list of resources Codes: matlab_examples.m, dice.m

4 4 Overview of MATLAB MATLAB: a language and programming environment with integrated graphics, extensive function libraries emphasizing array (vector/matrix) operations with dynamic allocation of memory for arrays MATLAB may be used interactively or via.m files interactively: at the command line.m files: scripts (sets of commands) or functions MATLAB codes are interpreted they may be slow compared with compiled code (C, Fortran) MATLAB has some unusual features e.g. data are always matrices (arrays) scalars are 1 1 arrays e.g. type defaults to data double precision floating point

5 5 Numerical Errors: 1. Floating point errors Floating point 3 is an approximate representation of the reals IEEE double precision is the standard used by MATLAB this uses base 2 with 64 bits (0s or 1s) per number there are infinitely many reals but a finite number of floats the approximation produces range error and rounding error Range error is due to there being largest and smallest floats underflow: x replaced by 0 overflow: x replaced by Inf Rounding error: is due to the discrete spaces between floats results are rounded to the nearest float the fractional error is 1 2 ɛ m ɛ m = is the machine epsilon/precision this is the built-in constant eps in MATLAB but this may be important, e.g *eps-1 gives zero Undefined operations (e.g. 0/0) produce NaN (not a number) NaNs propagate (e.g. NaN+x gives NaN for all x) 3 For more info see: What Every Computer Scientist Should Know About Floating-Point Arithmetic by David Goldberg and 20.1 of Numerical Recipes or OLEx1622 Numbers and Numerics

6 6 Numerical Errors: 2. Truncation errors Truncation error: approximations in the numerical method e.g. the forward difference approximation to the derivative: f f (x + h) f (x) (x) (in general for h x) (1) h to quantify the approximation consider the Taylor series: f (x + h) = f (x) + hf (x) + 1 2! h2 f (x) +... (2) f f (x + h) f (x) (x) = 1 h 2 hf (x) +... (3) the largest error term is proportional to h and we write: f (x) = f (x + h) f (x) h we say the local truncation error is order h Truncation error limits accuracy i.e. how close you are to the correct answer + O(h) (4)

7 7 Review of MATLAB (assumed knowledge) General: (The MATLAB examples in this section are in matlab_examples.m) y=[1 2 3]; z=y ; disp(y); disp(z); y^2 % A common error y.^2 z*y v=1:10 w=pi format long; w format long; w These examples illustrate: matrix operations are used by default the product of L M and M N arrays is size L N the. (full stop) enforces element-by element operations there are handy built-in constants the full number of digits of precision is seen with format long row and column vectors are different row and column vectors of length L: 1 L and L 1 arrays to convert between them: the transpose operator (a prime) a semi-colon at the end of a line suppresses output the : (colon) operator is a simple way to generate vectors

8 8 Program control: Conditionals e.g. if-else statements x=input( Value of integer x? ); if x==0 disp( x is equal to zero ); else if x>0 disp( x is positive ); else disp( x is negative ); end end note the use of the relational operators == and > note also the match between the indenting and the logic Other control structures we will often use for loops e.g. tau=0.1; LENGTH=10; for n=1:length time(n)=tau*n; end the loop should include only statements depending on n you need also to be familiar with nested loops we will occasionally use while and switch

9 9 Array operations: MATLAB started as a MATrix LABoratory operations are array (matrix) operations by default array operations are relatively fast rather than our loop use: tau=0.1; LENGTH=50000; time2=tau*(1:length); MATLAB has built-in array generation functions linspace() and logspace() generate row vectors ones(), zeros, eye(), diag() generate simple arrays The operator find is very useful it locates indices of array elements matching a condition 0.5 x1=-0.5:0.05:0.5; x2=x1; L=length(x1); x2(find(abs(x1)<0.25))=0; plot(1:l,x1, o,1:l,x2, + ); xlabel( Array index ); ylabel( Array value ); Array value Array index

10 10 The dot operator forces element-wise operations e.g. x.^2 this command squares the components of the vector x whereas x^2 gives an error if x is not a square array The colon operator is useful to define vectors the colon also identifies all indices in a dimension e.g. x=ones(5); % x is a 5 x 5 matrix of ones y=x(:,1); % y is a 5 x 1 vector of ones the semi-colon can define column vectors e.g. x=[1;2;3]; as well as suppressing output (at the end of a statement)

11 11 Linear algebra: An example of solution of a linear system: A=rand(3,3) % This is the same as rand(3) b=rand(3,1) x=a\b res=a*x-b max(res) % Compare with the machine precision/epsilon eps... disp([ eps =,num2str(eps)]); this example sets up and solves a 3 3 linear system Ax = b where A and b contain random numbers between 0 and 1 the x=a\b command solves the system in MATLAB the residual res is comparable to the machine precision 4 the determinant and the eigenvectors of A are given by eig(): det(a) eig(a) [V,D]=eig(A) 4 The fractional spacing of floating point numbers see later in this lecture.

12 12 Plotting: The basic command is plot(x,y): % Plotting example x=0:0.1:2*pi; f1=sin(x); f2=cos(x); plot(x,f1,x,f2); xlabel( x ) ylabel( sin(x), cos(x) ) 1 A simple plot in MATLAB... always label your axes! 0.5 y x

13 13 Plotting: Also: semilogx(x,y), semilogy(x,y), loglog(x,y) use these if there is a large range of values in x/y/both use semilogy(x,y) if you have exponential behaviour in y use loglog(x,y) if you have power-law behaviour For plotting a surface use e.g. contourf or surfc 1 colormap(hot); y=-pi:0.1:pi; z=sin(x) *cos(y); surfc(x,y,z); axis([min(x) max(x) min(y)... max(y)]); xlabel( x ); ylabel( y ); zlabel( z ); z y x 4 6

14 14 Writing functions in MATLAB: A simple function (dice.m) % dice.m % Function returning a specified number of random integers, each % from one to six. % % Inputs: % ndice - number of random integers required % Outputs: % ran6 - row vector with the integers function ran6 = dice(ndice) ran6=floor(6*rand(1,ndice))+1; this code goes in the separate file dice.m example of interactive use of dice.m in MATLAB: N=10000; test=dice(n); x=1:6; hist(test,x) xlabel( Value ); ylabel( Number ); % Generate throws of a die % Horizontal axis values % Histogram of results

15 Number Value Example of defining and calling an anonymous function x=[0:0.1:10]; cauchy=@(x,a) 1./pi./(1+(x-a).^2); plot(x,cauchy(x,5)); xlabel( x ); ylabel( y ); y x this code can be written at the command line or put a script

16 16 MATLAB dos and don ts: Keep your lines short use the ellipsis... to break long lines also shorten lines by defining sub-expressions separately Understand the basics of order of operations operations generally occur L to R use this correctly and avoid over-bracketing Use the e scientific notation in your code e.g. e=1.602e+19 in your code but use in writing Write clear code include comments as required

17 17 Resources for learning MATLAB: Read the documentation available within MATLAB: doc plot opens a graphical browser with information whos x in-terminal information on a variable help plot in-terminal information on a command Use the e-texts on the Resources page on elearning: Hahn & Valentine Essential MATLAB for Engineers Chapter 1 of Garcia Numerical Methods for Physics Refer to the MATLAB web site (mathworks.com) as well as other web sites on MATLAB You need to be on top of the MATLAB programming! Lab 1 is a MATLAB review/refresher based on Chapter 1 of Hahn & Valentine the lab question sheets are all on elearning

18 18 Mike s debugging tips: 1. Pay attention to error messages they are meaningful think about what the messages mean 2. Remove unnecessary parts of your code strip it back to simple clear code 3. Check variable values by printing them to screen in interactive mode type the variable name for variables in functions use e.g. disp([ x =,num2str(x)]) or remove semicolons! if there are large numbers of values, plot them think about what the values mean 4. Halt program execution prematurely when there are errors halt a loop with a break statement halt a function with a return statement use this to determine when an error occurs 5. Think again: the machine is just following your instructions

19 19 Appendix: Codes % matlab examples.m % % An example of a script: the MATLAB examples from lecture 1. This % script is not intended to be run independently (although it will % run without errors excepting an intended error). % Clear memory and only show a few digits clear all; format short; % Data x=1; whos x; y=[1 2 3]; z=y ; disp(y); disp(z); % Array operations, constants, digits of precision yˆ2 % A common error y.ˆ2 z y v=1:10 w=pi format long w format short % Use of ellipsis to line break x=... 2;

20 20 % Graphical help browser doc % Program control % If else statements x=input( Value of integer x? ); if x==0 disp( x is equal to zero ); else if x>0 disp( x is positive ); else disp( x is negative ); end end % Loops tau=0.1; LENGTH=50000; for n=1:length time(n)=tau n; end % Array version use this! time2=tau (1:LENGTH); % Find elements of an array matching a condition find((time > 1) & (time < 1.2)) % Example in lecture x1= 0.5:0.05:0.5; x2=x1; L=length(x1); x2(find(abs(x1)<0.25))=0;

21 21 plot(1:l,x1, o,1:l,x2, + ); xlabel( Array index ); ylabel( Array value ); % Matrix algebra A=rand(3,3) % This is the same as rand(3) b=rand(3,1) x=a\b res=a x b max(res) % Compare with the machine precision/epsilon eps... disp([ eps =,num2str(eps)]); % What is the machine precision? disp([ eps 1 =,num2str(1+0.5 eps 1)]); % Example of calculating determinant, eigenvectors and values det(a) eig(a) [V,D]=eig(A) % 1 D plotting example x=0:0.1:2 pi; f1=sin(x); f2=cos(x); plot(x,f1,x,f2); xlabel( x ) ylabel( y ) title( A simple plot in MATLAB... always label your axes! ); % 2 D plotting examples colormap(hot); % Avoid the rainbow colormap! y= pi:0.1:pi; z=sin(x) cos(y);

22 22 % Filled contours... contourf(x,y,z); axis([min(x) max(x) min(y)... max(y)]); xlabel( x ); ylabel( y ); % Or a surface surfc(x,y,z); axis([min(x) max(x) min(y) max(y)]); xlabel( x ); ylabel( y ); zlabel( z ); % Functions see the file dice.m N=10000; test=dice(n); % Generate throws of a die x=1:6; % Horizontal axis values hist(test,x) % Histogram of results xlabel( Value ); ylabel( Number ); % Defining and calling an anonymous function x=[0:0.1:10]; cauchy=@(x,a) 1./pi./(1+(x a).ˆ2); plot(x,cauchy(x,5)); xlabel( x ); ylabel( y );

23 23 % dice.m % Function returning a specified number of random integers, each % from one to six. % % Inputs: % ndice number of random integers required % Outputs: % ran6 row vector with the integers function ran6 = dice(ndice) ran6=floor(6 rand(1,ndice))+1;

Introduction to MATLAB

Introduction to MATLAB ELG 3125 - Lab 1 Introduction to MATLAB TA: Chao Wang (cwang103@site.uottawa.ca) 2008 Fall ELG 3125 Signal and System Analysis P. 1 Do You Speak MATLAB? MATLAB - The Language of Technical Computing ELG

More information

Lecturer: Keyvan Dehmamy

Lecturer: Keyvan Dehmamy MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

More information

Laboratory 1 Octave Tutorial

Laboratory 1 Octave Tutorial Signals, Spectra and Signal Processing Laboratory 1 Octave Tutorial 1.1 Introduction The purpose of this lab 1 is to become familiar with the GNU Octave 2 software environment. 1.2 Octave Review All laboratory

More information

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems

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

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

Introduction to Matlab

Introduction to Matlab Introduction to Matlab What is Matlab The software program called Matlab (short for MATrix LABoratory) is arguably the world standard for engineering- mainly because of its ability to do very quick prototyping.

More information

Introduction to MATLAB programming: Fundamentals

Introduction to MATLAB programming: Fundamentals Introduction to MATLAB programming: Fundamentals Shan He School for Computational Science University of Birmingham Module 06-23836: Computational Modelling with MATLAB Outline Outline of Topics Why MATLAB?

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

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

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

More information

Stokes Modelling Workshop

Stokes Modelling Workshop Stokes Modelling Workshop 14/06/2016 Introduction to Matlab www.maths.nuigalway.ie/modellingworkshop16/files 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 1 / 16 Matlab As part of this crash

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

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

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab MATH 495.3 (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab Below is a screen similar to what you should see when you open Matlab. The command window is the large box to the right containing the

More information

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

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

Introduction to MATLAB

Introduction to MATLAB 58:110 Computer-Aided Engineering Spring 2005 Introduction to MATLAB Department of Mechanical and industrial engineering January 2005 Topics Introduction Running MATLAB and MATLAB Environment Getting help

More information

2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab November 22, 2013 Contents 1 Introduction to Matlab 1 1.1 What is Matlab.................................. 1 1.2 Matlab versus Maple............................... 2 1.3 Getting

More information

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Prof. Manoochehr Shirzaei. RaTlab.asu.edu RaTlab.asu.edu Introduction To MATLAB Introduction To MATLAB This lecture is an introduction of the basic MATLAB commands. We learn; Functions Procedures for naming and saving the user generated files

More information

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical

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 Math 339 Fall 2013 First, put the icon in the launcher: Drag and drop Now, open Matlab: * Current Folder * Command Window * Workspace * Command History Operations in Matlab Description:

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

Matlab Tutorial, CDS

Matlab Tutorial, CDS 29 September 2006 Arrays Built-in variables Outline Operations Linear algebra Polynomials Scripts and data management Help: command window Elisa (see Franco next slide), Matlab Tutorial, i.e. >> CDS110-101

More information

MATLAB GUIDE UMD PHYS401 SPRING 2011

MATLAB GUIDE UMD PHYS401 SPRING 2011 MATLAB GUIDE UMD PHYS401 SPRING 2011 Note that it is sometimes useful to add comments to your commands. You can do this with % : >> data=[3 5 9 6] %here is my comment data = 3 5 9 6 At any time you can

More information

Introduction to MATLAB

Introduction to MATLAB to MATLAB Spring 2019 to MATLAB Spring 2019 1 / 39 The Basics What is MATLAB? MATLAB Short for Matrix Laboratory matrix data structures are at the heart of programming in MATLAB We will consider arrays

More information

MATLAB TUTORIAL WORKSHEET

MATLAB TUTORIAL WORKSHEET MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent

More information

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:

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: Using MATLAB for Stochastic Simulation. Eric W. Hansen. Matlab Basics Introduction MATLAB (MATrix LABoratory) is a software package designed for efficient, reliable numerical computing. Using MATLAB greatly

More information

Introduction to PartSim and Matlab

Introduction to PartSim and Matlab NDSU Introduction to PartSim and Matlab pg 1 PartSim: www.partsim.com Introduction to PartSim and Matlab PartSim is a free on-line circuit simulator that we use in Circuits and Electronics. It works fairly

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 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

MATLAB GUIDE UMD PHYS401 SPRING 2012

MATLAB GUIDE UMD PHYS401 SPRING 2012 MATLAB GUIDE UMD PHYS40 SPRING 202 We will be using Matlab (or, equivalently, the free clone GNU/Octave) this semester to perform calculations involving matrices and vectors. This guide gives a brief introduction

More information

Lecture 2: Variables, Vectors and Matrices in MATLAB

Lecture 2: Variables, Vectors and Matrices in MATLAB Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables

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

Getting Started with MATLAB

Getting Started with MATLAB Getting Started with MATLAB Math 315, Fall 2003 Matlab is an interactive system for numerical computations. It is widely used in universities and industry, and has many advantages over languages such as

More information

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics.

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics. Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics. Starting MATLAB - On a PC, double click the MATLAB icon - On a LINUX/UNIX machine, enter the command:

More information

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

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming using familiar mathematical notation The name Matlab stands

More information

Mathworks (company that releases Matlab ) documentation website is:

Mathworks (company that releases Matlab ) documentation website is: 1 Getting Started The Mathematics Behind Biological Invasions Introduction to Matlab in UNIX Christina Cobbold and Tomas de Camino Beck as modified for UNIX by Fred Adler Logging in: This is what you do

More information

How to learn MATLAB? Some predefined variables

How to learn MATLAB? Some predefined variables ECE-S352 Lab 1 MATLAB Tutorial How to learn MATLAB? 1. MATLAB comes with good tutorial and detailed documents. a) Select MATLAB help from the MATLAB Help menu to open the help window. Follow MATLAB s Getting

More information

Chapter 1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,

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

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are

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

A Quick Tutorial on MATLAB. Zeeshan Ali

A Quick Tutorial on MATLAB. Zeeshan Ali A Quick Tutorial on MATLAB Zeeshan Ali MATLAB MATLAB is a software package for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It's name

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 for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA MATLAB for beginners KiJung Yoon, 1 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA 1 MATLAB Tutorial I What is a matrix? 1) A way of representation for data (# of

More information

AMTH142 Lecture 10. Scilab Graphs Floating Point Arithmetic

AMTH142 Lecture 10. Scilab Graphs Floating Point Arithmetic AMTH142 Lecture 1 Scilab Graphs Floating Point Arithmetic April 2, 27 Contents 1.1 Graphs in Scilab......................... 2 1.1.1 Simple Graphs...................... 2 1.1.2 Line Styles........................

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

Fundamentals of MATLAB Usage

Fundamentals of MATLAB Usage 수치해석기초 Fundamentals of MATLAB Usage 2008. 9 담당교수 : 주한규 joohan@snu.ac.kr, x9241, Rm 32-205 205 원자핵공학과 1 MATLAB Features MATLAB: Matrix Laboratory Process everything based on Matrix (array of numbers) Math

More information

1 Week 1: Basics of scientific programming I

1 Week 1: Basics of scientific programming I MTH739N/P/U: Topics in Scientific Computing Autumn 2016 1 Week 1: Basics of scientific programming I 1.1 Introduction The aim of this course is use computing software platforms to solve scientific and

More information

AM205: lecture 2. 1 These have been shifted to MD 323 for the rest of the semester.

AM205: lecture 2. 1 These have been shifted to MD 323 for the rest of the semester. AM205: lecture 2 Luna and Gary will hold a Python tutorial on Wednesday in 60 Oxford Street, Room 330 Assignment 1 will be posted this week Chris will hold office hours on Thursday (1:30pm 3:30pm, Pierce

More information

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

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise

More information

Introduction to Matlab

Introduction to Matlab NDSU Introduction to Matlab pg 1 Becoming familiar with MATLAB The console The editor The graphics windows The help menu Saving your data (diary) Solving N equations with N unknowns Least Squares Curve

More information

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

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD Introduction to MATLAB for Numerical Analysis and Mathematical Modeling Selis Önel, PhD Advantages over other programs Contains large number of functions that access numerical libraries (LINPACK, EISPACK)

More information

Teaching Manual Math 2131

Teaching Manual Math 2131 Math 2131 Linear Algebra Labs with MATLAB Math 2131 Linear algebra with Matlab Teaching Manual Math 2131 Contents Week 1 3 1 MATLAB Course Introduction 5 1.1 The MATLAB user interface...........................

More information

Chapter 2. MATLAB Basis

Chapter 2. MATLAB Basis Chapter MATLAB Basis Learning Objectives:. Write simple program modules to implement single numerical methods and algorithms. Use variables, operators, and control structures to implement simple sequential

More information

MATLAB GUIDE UMD PHYS375 FALL 2010

MATLAB GUIDE UMD PHYS375 FALL 2010 MATLAB GUIDE UMD PHYS375 FALL 200 DIRECTORIES Find the current directory you are in: >> pwd C:\Documents and Settings\ian\My Documents\MATLAB [Note that Matlab assigned this string of characters to a variable

More information

LabVIEW MathScript Quick Reference

LabVIEW MathScript Quick Reference Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics LabVIEW MathScript Quick Reference Hans-Petter Halvorsen, 2012.06.14 Faculty of Technology, Postboks

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

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

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

Floating-Point Numbers in Digital Computers

Floating-Point Numbers in Digital Computers POLYTECHNIC UNIVERSITY Department of Computer and Information Science Floating-Point Numbers in Digital Computers K. Ming Leung Abstract: We explain how floating-point numbers are represented and stored

More information

Matlab Tutorial. CS Scientific Computation. Fall /51

Matlab Tutorial. CS Scientific Computation. Fall /51 Matlab Tutorial CS 370 - Scientific Computation Fall 2015 1/51 Outline Matlab Overview Useful Commands Matrix Construction and Flow Control Script/Function Files Basic Graphics 2/51 Getting to Matlab Everyone

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

Getting started with MATLAB

Getting started with MATLAB Sapienza University of Rome Department of economics and law Advanced Monetary Theory and Policy EPOS 2013/14 Getting started with MATLAB Giovanni Di Bartolomeo giovanni.dibartolomeo@uniroma1.it Outline

More information

Floating-Point Numbers in Digital Computers

Floating-Point Numbers in Digital Computers POLYTECHNIC UNIVERSITY Department of Computer and Information Science Floating-Point Numbers in Digital Computers K. Ming Leung Abstract: We explain how floating-point numbers are represented and stored

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

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr A0B17MTB Matlab Part #1 Miloslav Čapek miloslav.capek@fel.cvut.cz Filip Kozák, Viktor Adler, Pavel Valtr Department of Electromagnetic Field B2-626, Prague You will learn Scalars, vectors, matrices (class

More information

Matrix Manipula;on with MatLab

Matrix Manipula;on with MatLab Laboratory of Image Processing Matrix Manipula;on with MatLab Pier Luigi Mazzeo pierluigi.mazzeo@cnr.it Goals Introduce the Notion of Variables & Data Types. Master Arrays manipulation Learn Arrays Mathematical

More information

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student

More information

Assignment 02 (Due: Monday, February 1, 2016)

Assignment 02 (Due: Monday, February 1, 2016) Assignment 02 (Due: Monday, February 1, 2016) CSCE 155N 1 Lab Objectives Improve your understanding of arrays and array operations Differentiate array operators and matrix operators Create, access, modify,

More information

INTRODUCTION TO SCIENCIFIC & ENGINEERING COMPUTING BIL 108E, CRN23320

INTRODUCTION TO SCIENCIFIC & ENGINEERING COMPUTING BIL 108E, CRN23320 INTRODUCTION TO SCIENCIFIC & ENGINEERING COMPUTING BIL 108E, CRN23320 Assoc. Prof. Dr. Hilmi Berk Çelikoğlu Dr. S.Gökhan Technical University of Istanbul March 03, 2010 TENTATIVE SCHEDULE Week Date Topics

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

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

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots

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

A Tour of Matlab for Math 496, Section 6

A Tour of Matlab for Math 496, Section 6 A Tour of Matlab for Math 496, Section 6 Thomas Shores Department of Mathematics University of Nebraska Spring 2006 What is Matlab? Matlab is 1. An interactive system for numerical computation. 2. A programmable

More information

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

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx 1 of 9 FreeMat Tutorial FreeMat is a general purpose matrix calculator. It allows you to enter matrices and then perform operations on them in the same way you would write the operations on paper. This

More information

What is Matlab? A software environment for interactive numerical computations

What is Matlab? A software environment for interactive numerical computations What is Matlab? A software environment for interactive numerical computations Examples: Matrix computations and linear algebra Solving nonlinear equations Numerical solution of differential equations Mathematical

More information

MATLAB Premier. Asst. Prof. Dr. Melik DÖLEN. Middle East Technical University Department of Mechanical Engineering 10/30/04 ME 304 1

MATLAB Premier. Asst. Prof. Dr. Melik DÖLEN. Middle East Technical University Department of Mechanical Engineering 10/30/04 ME 304 1 MATLAB Premier Asst. Prof. Dr. Melik DÖLEN Middle East Technical University Department of Mechanical Engineering 0/0/04 ME 04 Outline! Introduction! Basic Features of MATLAB! Prompt Level and Basic Aritmetic

More information

Getting Started with Matlab

Getting Started with Matlab Chapter Getting Started with Matlab The computational examples and exercises in this book have been computed using Matlab, which is an interactive system designed specifically for scientific computation

More information

Binary floating point encodings

Binary floating point encodings Week 1: Wednesday, Jan 25 Binary floating point encodings Binary floating point arithmetic is essentially scientific notation. Where in decimal scientific notation we write in floating point, we write

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

Introduction to Matlab

Introduction to Matlab Introduction to Matlab What is Matlab? Matlab is a commercial "Matrix Laboratory" package which operates as an interactive programming environment. Matlab is available for PC's, Macintosh and UNIX systems.

More information

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

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003 Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 About MATLAB MATLAB (MATrix LABoratory) is a high level language made for: Numerical Computation (Technical computing)

More information

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing SECTION 1: INTRODUCTION ENGR 112 Introduction to Engineering Computing 2 Course Overview What is Programming? 3 Programming The implementation of algorithms in a particular computer programming language

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

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

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

Floating-point numbers. Phys 420/580 Lecture 6

Floating-point numbers. Phys 420/580 Lecture 6 Floating-point numbers Phys 420/580 Lecture 6 Random walk CA Activate a single cell at site i = 0 For all subsequent times steps, let the active site wander to i := i ± 1 with equal probability Random

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

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Stefan Güttel September 22, 2017 Contents 1 Introduction 2 2 Matrices and Arrays 2 3 Expressions 3 4 Basic Linear Algebra commands 4 5 Graphics 5 6 Programming Scripts 6 7 Functions

More information

CME 192: Introduction to Matlab

CME 192: Introduction to Matlab CME 192: Introduction to Matlab Matlab Basics Brett Naul January 15, 2015 Recap Using the command window interactively Variables: Assignment, Identifier rules, Workspace, command who and whos Setting the

More information

Essential MATLAB for Engineers and Scientists

Essential MATLAB for Engineers and Scientists Essential MATLAB for Engineers and Scientists Third edition Brian D. Hahn and Daniel T. Valentine ELSEVIER AMSTERDAM BOSTON HEIDELBERG LONDON NEW YORK OXFORD PARIS SAN DIEGO SAN FRANCISCO SINGAPORE SYDNEY

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

CS335. Matlab Tutorial. CS335 - Computational Methods in Business and Finance. Fall 2016

CS335. Matlab Tutorial. CS335 - Computational Methods in Business and Finance. Fall 2016 Matlab Tutorial - Computational Methods in Business and Finance Fall 2016 1 / 51 Outline Matlab Overview Useful Commands Matrix Construction and Flow Control Script/Function Files Basic Graphics 2 / 51

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

Introduction to MATLAB

Introduction to MATLAB CHEE MATLAB Tutorial Introduction to MATLAB Introduction In this tutorial, you will learn how to enter matrices and perform some matrix operations using MATLAB. MATLAB is an interactive program for numerical

More information

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB? Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system

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

Introduction to MATLAB Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse

More information

Scientific Computing Numerical Computing

Scientific Computing Numerical Computing Scientific Computing Numerical Computing Aleksandar Donev Courant Institute, NYU 1 donev@courant.nyu.edu 1 Course MATH-GA.2043 or CSCI-GA.2112, Spring 2012 January 26th, 2012 A. Donev (Courant Institute)

More information