IC3003 B ASIC S CIENTIFIC C OMPUTING Lecture 1 Monday 08:30-11:30 U204a.

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Introduction to Matlab
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB ME1107 Y Yan Reference: MATLAB for Engineers by Holly Moore (Pearson Prentice Hall)
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to MATLAB
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (2): MATLAB Environment (Chapter 1)
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Scientific Computing Introduction to Matlab Programming.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
The Hong Kong Polytechnic University Industrial Centre MatLAB Lesson 1 : Overview & Environment Edward Cheung Room W311g.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
ECE 351 M ATLAB I NTRODUCTION ( BY T EACHING A SSISTANTS )
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Matlab for Engineers Matlab Environment Chapter 2.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
ECE 1304 Introduction to Electrical and Computer Engineering
Lecture: MATLAB Chapter 1 Introduction
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
Lecture 2 Introduction to MATLAB
Communication and Coding Theory Lab(CS491)
INTRODUCTION TO MATLAB
Experiment No. (1) - an introduction to MATLAB
CS 111 Introduction to Computing in Engineering and Science
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

IC3003 B ASIC S CIENTIFIC C OMPUTING Lecture 1 Monday 08:30-11:30 U204a

2 Assessment Weighting 30% Test – (30 Multiple Choice in 45 mins) 40% Assignment (8 Exercises) 30% Log sheet (Workshop Report) including performance Lecture Notes & Reference Web site Using POLYU webmail to submit assignments C OURSE O UTLINE

3 After completed the course, the students should be able to 1. Understand the MATLAB can solve mathematical & Scientific problem 2. Analyze the data by using 2D and 3D visualization plots to enhance graphic presentation 3. Import and export data with other application 4. Use M-file programming to construct user defined math functions 5. Construct programs with flow control functions 6. Construct graphic user interface O UTCOME – BASE L EARNING

L ECTURE 1 I NTRODUCTION

5 MATLAB stands for Matrix Laboratory Basic Scientific Calculation (Linear Algebra, Matrix ) Applied Pure Mathematics (Calculus, Partial Fraction) 2D Plotting 3D Visualization Curve Fitting File Input / Output Graphic User Interface, etc……

6 I NTRODUCTION MATLAB software version - MATLAB R2008a The software icon in desktop If you use previous version, it cannot open the file Another method: Use Notepad to save all file in the M-File format (XXX.m) It cannot run in the Notepad, you just check the solution in MATLAB

7 I NTRODUCTION MATLAB software interface Command Window Current Directory / Workspace Command History

8 I NTRODUCTION Current Directory / Workspace Files in Current Directory

9 I NTRODUCTION Current Directory / Workspace Store the variables not saved The data is not saved after you exit MATLAB. All data can be saved by : “save Workspace As” 1.Selecting “save Workspace As” from the File menu save 2.Using save function – This is used for saving all data to MAT-File

10 I NTRODUCTION Command History Display all previous command Double click the commands in command history window will also re-activate that command

11 I NTRODUCTION Command Window Show the result

12 I NTRODUCTION Command Window format compact MATLAB inserts a blank line to separate command lines. You can eliminate it by using format compact Type the command Show the result Pi or  Command Remove blank lineFormat compact Format long (15 digits) Format short (5 digits) 3.14Format bank (2 decimal place) 335/113Format rat (Ratio)

13 I NTRODUCTION M-File Programming

14 I NTRODUCTION M-File Programming The new window pump up

15 I NTRODUCTION M-File programming can be saved and submitted the solution in a clear way M-File programming has script or function file (stand alone file) Command windows is only to check the solution directly Note: When you do the exercise or assignment, you should use M-File to run the solution and you can see the answer and error in the command window

16 I NTRODUCTION Simple Mathematics Functions +, -, *, /, \,^ pi=  sin(pi) cos(pi) tan(pi) sqrt(100) factorial(5) factor(100) primes(100) randperm(10)

17 I NTRODUCTION Round floating point numbers to integer round >>round(10.5) ans= 11 >>round(10.4) ans= 10 fix >>fix(-10.5) ans= -10 >>fix(10.4) ans= 10

18 I NTRODUCTION Round floating point numbers to integer ceil >>ceil(10.5) ans= 11 >>ceil(-10.4) ans= -10 floor >>floor(10.5) ans= 10 >>floor(-10.4) ans= -11

I NTRODUCTION It is convenience since it allows multiple statements to be executed without printing the intermediate results. You can suppress the result by using “semicolon - ;” at the end of each function, >>pi/3; >>sin(ans)/cos(ans); >> ans-tan(pi/3); 19

V ARIABLE MATLAB variables are created when they appear on the left of an equal sign >>variable = expression Variables include Scalars Scalars Vectors Vectors Matrices Matrices Strings Strings Characteristics of MATLAB variables: Variable names must begin with an alphanumeric letter Following that, any number of letters, digits and underscores can be added, but only the first 19 characters are retained “x” “X” MATLAB variable names are case sensitive so “x” and “X” are different variables 20

S CALARS scalar one row and one column A scalar is a variable with one row and one column >>a=4; >>b=5; >>c=a+b; The following statements demonstrate scalar operation >>x=6; >>y=3; >>a=x+y; >>s=x-y; >>m=x*y; >>d=x/y; >>i=y\x; >>p=x^y; Scalar OperationStatement Additiona=x+y Subtractions=x-y Multiplicationm=x*y Divisiond=x/y Inversei=x\y Powerp=x^y 21

S CALARS Example: Compute 5sin(2.5 3-pi )+1/75 >>5*sin(2.5^(3-pi))+1/75 ans= Example: Compute 1\3(cos3 pi ) >>1\3*cos(3^pi) ans=

V ECTORS vector one row or one column A vector is a matrix with either one row or one column Creating vector of the following statements Ones To create a row vector of length 5 with single row >>x=ones(1,5) x= Zeros To create a column vector of length 5 with single row >>y=zeros(5,1) x= 0 The first one is no. of row The second one is no. of column 23

V ECTORS Linspace To create a linearly spaced element >>x=linspace(1,5,5) x= Logspace To create a logarithmically spaced element >>y=logspace(1,5,5) y= The third argument of both linspace and logspace is optional. The third argument is the number of elements to be used between the range specified with the first and second arguments 24

V ECTORS Addressing vector elements Location of vector can be address by using >>x=linspace(11,15,3) x= >>x(2) ans= 13 >>x(end) ans= 15 25

V ECTORS Increasing the size of vector We can also increase the size of vector by simply assigning a value to an element >>x=linspace(1,5,5) x= >>x(7)= -9 x= X(6) is assigned to zero 26

V ECTORS Colon notation The format of this command is shown as below: >>x=xbegin:dx:xend Or >> x=xbegin:xend Where xbegin and xend are the range of values covered by elements of the x vector and dx is the optional increment. The default value of dx is (unit increment). The numbers xbegin, dx and xend may not be integers. >>x=1.1:5.1 x=

V ECTORS Colon notation Location of vector can be address by using >>x=1:10; >>x(1:2:end) ans= To create a column vector, append the transpose operator to the end of the vector-creating expression >>y=(1:5)' y=

M ATRICES matrix more than one row and one column A matrix is a variable with more than one row and one column Creating 2 by 2 matrix >>A=[1 2; 3 4] A= Creating 2 by 3 matrix >>A=[1 2 3; 4 5 6] A=

M ATRICES Addressing matrix elements >>A=[1 2 3; 4 5 6; 7 8 9] A= >>A(2,3) ans= 6 >>A(3,2)=-5 A= The first one is no. of row The second one is no. of column 30

S TRINGS string A string is a word >>a='test' a= test Converts to ASCII code for simple calculation >>a+a ans= Apply the string >>[a a] ans= testtest 31

M ATHEMATICAL O PERATION Addition >>A=[1 1 1; 1 2 3; 1 3 6]; >>B=[8 1 6; 3 5 7; 4 9 2]; >>X=A+B X= Subtraction >>Y=X-A Y= Addition & Subtraction require both matrices to have same dimension. If dimensions are incompatible, an error will display >>C=[1:3; 4:6]; >>X=A+C ??? Error using ==> plus Matrix dimensions must agree. 32

M ATHEMATICAL O PERATION Multiplication >>u=[2 3 4]; >>v=[-2 0 2]'; >>x=u*v x= 4 >>x=v*u x= u*v  v*u 33

M ATHEMATICAL O PERATION Element by Element Operations(.* or./ or.^) >>a=[1 2 3]; b=[2 5 8]; >>a+b ans= Let’s try to multiply >>a*b ??? Error using ==> mtimes Inner matrix dimensions must agree. >>a*b' ans= 36 It needs to transpose the second vector 34

M ATHEMATICAL O PERATION Element by Element Operations(.* or./ or.^) >>a=[1 2 3]; b=[2 5 8]; >>a.*b ans= It also needs to apply at.^ >>a.^2 ans= 149 If forget the period will lead to : >>a^2 ??? Error using ==> mpower Matrix must be square. 35

M ATHEMATICAL O PERATION Solving Linear Equation ax + by + cz = p dx + ey + fz = q gx + hy + iz = r Set Matrices, abcxp A=def,B=y and C=q ghizr A  B = C B=A -1 C 36

M ATHEMATICAL O PERATION For example, x + y + z = 0 x - 2y + 2z = 4 x + 2y - z = 2 Set Matrices, 111x0 A=1 -22,B=y and C= z2 >>A=[1 1 1;1 -2 2; ]; >>C=[0 4 2]'; >>B=inv(A)*C B= Therefore the linear system has one solution: X=4, y=-2 and z=-2 37