ENGR 105: Introduction to Scientific Computing. Dr. Graham. E. Wabiszewski

Similar documents
Introduction to Engineering gii

Lecture 1. Introduction to course, Welcome to Engineering, What is Programming and Why is this the first thing being covered in Engineering?

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Welcome to EGR 106 Foundations of Engineering II

Chapter 1 Introduction to MATLAB

AMS 27L LAB #1 Winter 2009

Introduction to MatLab. Introduction to MatLab K. Craig 1

CVEN 302. Computer Applications in Engineering and Construction. Dr. Tony Cahill Environmental and Water Resources Division

High-Performance Scientific Computing

Lab 1 - Worksheet Spring 2013

ME 121 MATLAB Lesson 01 Introduction to MATLAB

Introduction to Matlab

Introduction to MATLAB

Introduction to MATLAB

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

ECE 3793 Matlab Project 1

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

To start using Matlab, you only need be concerned with the command window for now.

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

ELEMENTARY MATLAB PROGRAMMING

Computers and programming languages introduction

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

ENGR 105: Introduction to Scientific Computing. Dr. Graham. E. Wabiszewski

Lecture 27: Learning from relational data

Matlab Programming Introduction 1 2

CISC 124: Introduction To Computing Science II

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

Basic MATLAB Tutorial

Introduction to MATLAB

MATLAB TUTORIAL WORKSHEET

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

1. Register an account on: using your Oxford address

MatLab Just a beginning

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

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

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

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

Announcements. 1. Forms to return today after class:

Matlab Programming MET 164 1/24

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

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

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

Introduction to Matlab

MATLAB - Lecture # 4

Mathematical Operations with Arrays and Matrices

1 Introduction to Matlab

MATLAB QUICK START TUTORIAL

61A Lecture 4. Monday, September 9

EGR 111 Introduction to MATLAB

CS 241 Data Organization. August 21, 2018

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs).

CS 101: Computer Programming and Utilization. Abhiram Ranade

College Algebra. Cartesian Coordinates and Graphs. Dr. Nguyen August 22, Department of Mathematics UK

1 Week 1: Basics of scientific programming I

Menu. Class 1: Introduction. Staff. Course Structure and Expectations. Contacting Us. Contacting You

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Introduction to MATLAB Practical 1

Lecture 1: What is MATLAB?

1 Overview of the standard Matlab syntax

MATLAB Demo. Preliminaries and Getting Started with Matlab

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

CSC 101: Lab Manual#9 Machine Language and the CPU (largely based on the work of Prof. William Turkett) Lab due date: 5:00pm, day after lab session

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

Matlab = Matrix Laboratory. It is designed to be great at handling matrices.

Scientific Computing: Lecture 1

Numerical Analysis First Term Dr. Selcuk CANKURT

An Introduction to Numerical Methods

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

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


CSC209. Software Tools and Systems Programming.

University of Engineering and Technology, Taxila Department of Civil Engineering

Lecture 1. Course Overview Types & Expressions

ELEC ENG 4CL4 CONTROL SYSTEM DESIGN

Exercises: Instructions and Advice

Fall 2017: Numerical Methods I Assignment 1 (due Sep. 21, 2017)

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

Lab. Manual. Practical Special Topics (Matlab Programming) (EngE416) Prepared By Dr. Emad Saeid

Class #15: Experiment Introduction to Matlab

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

MATH 2650/ Intro to Scientific Computation - Fall Lab 1: Starting with MATLAB. Script Files

Programming in QBasic

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

Graphical Presentation of Data

Chapter 1 Introduction to MATLAB

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

CS 240 Fall Mike Lam, Professor. Just-for-fun survey:

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

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

Complex Dynamic Systems

What is Matlab? The command line Variables Operators Functions

Weekly Discussion Sections & Readings

Introduction to MATLAB

MATH 2221 A Mathematics Laboratory II

Lab 1 Intro to MATLAB and FreeMat

22-Functions Part 1 text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

MATH 2221A Mathematics Laboratory II

Transcription:

ENGR 105: Introduction to Scientific Computing Machine Model, Matlab Interface, Built-in Functions, and Arrays Dr. Graham. E. Wabiszewski ENGR 105 Lecture 02

Answers to questions from last lecture Office hours TA Mr. Jimmy Paulos: Tuesdays from 3-4pm, location TBD Dr. Graham Wabiszewski: Fridays from 4-5pm, 272 Towne Hypothetically, could everyone in the class receive an A? Yes! You are competing with yourself and your own knowledge. Help your classmates - but no copying! ENGR 105 Lecture 02 2

Answers to questions from last lecture Lab quizzes No Googling during the lab quizzes - it should be just you and Canvas First lab quiz will be on 9/11 Course book / Ch.1 Physical copy available at UPenn bookstore Digital copy should eventually be available through the UPenn library - no firm date as to when this will happen A pdf version of Ch. 1 will be uploaded to Canvas tonight ENGR 105 Lecture 02 3

Answers to questions from last lecture Can I give you the code to 207 Moore? Yes. The code is 5-3-4-2-1 Do not use the space while other classes are occupying it, see the following for the reservation schedule: https://www.seas.upenn.edu/cets/forms/labrequest/availability.php?room=moore_207_public ENGR 105 Lecture 02 4

Answers to questions from last lecture Can I resubmit an assignment before the due date? Yes! Details of this can be found at: http://guides.instructure.com/s/2204/m/4212/l/41972-howdo-i-submit-an-online-assignment You may also find How do I upload a file to my assignment submission helpful: http://guides.instructure.com/s/2204/m/4212/l/54353-howdo-i-upload-a-file-to-my-assignment-submission ENGR 105 Lecture 02 5

Upcoming work First homework assignment Will be uploaded on ~Tuesday, 9/3 Will be due Wednesday, 9/11 Reading requirements o Ch. 1 & Ch. 2 of Essential Matlab o Article Everything I need to know about pair programming I learned in kindergarten ENGR 105 Lecture 02 6

Questions? Any questions? ENGR 105 Lecture 02 7

Results of the initial assessment Have you used Matlab before this course? ENGR 105 Lecture 02 8

Results of the initial assessment How would you rate your current Matlab expertise? ENGR 105 Lecture 02 9

Results of the initial assessment correct ENGR 105 Lecture 02 10

Results of the initial assessment 38% 59% correct ENGR 105 Lecture 02 11

Results of the initial assessment 92% correct ENGR 105 Lecture 02 12

Results of the initial assessment 51% correct 40% ENGR 105 Lecture 02 13

Results of the initial assessment Many students in ENGR 105 are new to Matlab Good grasp of math Great at inferring syntax ENGR 105 Lecture 02 14

How does a computer process information? Peripherals / user interface High density storage (hard drive) Power supply Motherboard and central processing unit (CPU) Random access memory (RAM) ENGR 105 Lecture 02 15

How does a computer process information? Voltages Applications High level code Assembly/machine code Microprocessor Individual transistors ENGR 105 Lecture 02 16

Calculations at the transistor scale Cross-section of a field effect transistor Corresponding IV characteristics ENGR 105 Lecture 02 17

Microprocessor model What if we were programming at the machine/assembly language level? Memory CPU Instructions $0-20.04 $1 10.56 $2-7.678 $3 8.0 $4 3.14159 $5 9 0 ADD 0, -20.04, $0 1 ADD 0, 10.56 $1 2 ADD $0, $1, $0 3 ADD $0, $4, $0 4 ADD $0, $5, $0 5 DIV $0, 5, $0 Assembly Language ENGR 105 Lecture 02 18

High level language programming Programming in assembly language is a pain - that s why we developed higher level languages like Java, C and Matlab and developed programs called interpreters/compilers to translate from human readable text to low level instructions. sum = 0; for i = 1:500 sum = sum + x(i); end avgval= sum/500; High Level Code (machine independent) Compiler/ Interpreter 0 ADD 0, 0, $1 1 ADD 0, 0, $2 2 ADD $3[$1], $2, $2 3 ADD $1, 1, $1 4 LT $1, 500, 2 5 DIV $2, 500, $2 Assembly Code (machine dependent) ENGR 105 Lecture 02 19

Why Matlab? Matlab (Matrix Laboratory) is descended in part from the programming language FORTRAN which was designed to support FORmula TRANslation. As such Matlab makes it easy to evaluate complex mathematical expressions. 1 million users in 2004 IBM, 1953 Alternative to assembly language University of New Mexico, 1970 s Alternative to Fortran ENGR 105 Lecture 02 20

Matlab help system You should get familiar with the MATLAB help system - it contains documentation on all of Matlab s functions I often use the Google method ENGR 105 Lecture 02 21

Matlab file exchange Great source of pre-built code and code examples http://www.mathworks.com/matlabcentral/fileexcha nge/ ENGR 105 Lecture 02 22

A brief introduction to Matlab Layout of the Matlab interface (2012 and 2013) Current workspace variables Editor - docked in this case (write scripts/m-files) Command history (code executed from the command window) Command window (test bits of code, call scripts) ENGR 105 Lecture 02 23

Statements The statement is the most basic kind of MATLAB command Foo = x^2 + sin(5*y) / exp(67*z); It evaluates an expression the right hand side of the equation - and assigns the result to a named variable the left hand side of the equation. The semicolon at the end is optional. When present it suppresses output that would be printed to the command line. ENGR 105 Lecture 02 24

Built-in Matlab functions Befitting it s role as the premier scientific computing environment - Matlab has thousands of built-in functions for evaluating common mathematical and statistical functions Sin(x), cos(x), exp(x), log(x), atan(x), cosh(x), sinh(x), mean(x), median(x), etc. Any function you can think of and many that you haven t imagined yet ENGR 105 Lecture 02 25

Array basics In addition to normal, scalar, variables MATLAB is designed to work with arrays which you can think of as sequences of numbers. x = [1, 3, 9, 11, -10.2]; create array with 5 numbers You can access members of the array via indexing Foo = x(3); extracts third element in the array x(2) = 27; reassign second element in the array Arrays are fundamental to MATLAB and we will have a lot more to say about them. ENGR 105 Lecture 02 26

Creating arrays with slice notation Since arrays are used so extensively in MATLAB there is special syntax for creating sequences x = 1:15; creates an array with the numbers 1 through 15 x = 4:2:28; creates an array starting at 4 and going up by 2 until it gets to 28 x = -1.3:0.1:1.3; creates an array starting at -1.3 and going up by 0.1 until it gets to 1.3 ENGR 105 Lecture 02 27

Creating arrays with slice notation Say I type x = 1:2:6; into the command line. What is the last value of array x? Answer: 5 x = [1,3,5] Matlab will not include values above the upper bound! ENGR 105 Lecture 02 28

Operations on arrays You can perform mathematical operations on arrays just as you can scalar values. x = 0:0.1:10; create an array of values y = exp(5*x).*sin(x); evaluate an expression on every element in the array producing a new array called y plot (x, y); produce a plot ENGR 105 Lecture 02 29

Operations on arrays You can add two arrays in Matlab as long as they are the same size - if they are not you will get an error x = [1 2 3 4 5]; y = [7 8 9 10 11]; z = x + y; pointwise addition adds corresponding elements Subtraction works the same way ENGR 105 Lecture 02 30

Operations on arrays For multiplication and division the syntax is a little different z = x.*y; pointwise multiplication z = x./y; pointwise division Here you need the. to specify a pointwise operation instead of matrix multiplication or division (we will explore this later) ENGR 105 Lecture 02 31

Operations on arrays Almost all of Matlab s built in functions will accept arrays as arguments and perform their operation in a pointwise manner x = 1:10:1000; y = sqrt(x); compute the square root of each element in the array x ENGR 105 Lecture 02 32

Scripts Sequences of MATLAB commands can be stored in script files and then executed by invoking the name of the script on the command line The effect of executing the script is pretty much the same as typing the commands in the file in one after another into the command window Demo: writing a script ENGR 105 Lecture 02 33

Current working directory When you are working with MATLAB you need to be aware that there is a current working directory which you can set You should begin by creating a directory in some appropriate part of your file system, and then setting your working directory to that location All the files you create will be stored there by default and that is where MATLAB will look first when you invoke scripts by name ENGR 105 Lecture 02 34