MA/CS 375 Fall 2002 Lecture 2. Motivation for Suffering All This Math and Stuff Try the Actor demo from www.vividimage.co.uk.

Slides:



Advertisements
Similar presentations
15. Python - Modules A module allows you to logically organize your Python code. Grouping related code into a module makes the code easier to understand.
Advertisements

Lecture 5.
Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Functions in MatLab Create a new folder on your Z:drive called MatLab_Class24 Start MatLab and change your current directory to MatLab_Class24 Topics:
MATLAB ME1107 Y Yan Reference: MATLAB for Engineers by Holly Moore (Pearson Prentice Hall)
1 Python Chapter 2 © Samuel Marateck, After you install the compiler, an icon labeled IDLE (Python GUI) will appear on the screen. If you click.
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.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
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
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Math 15 Lecture 7 University of California, Merced Scilab A “Very” Short Introduction.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Computer Science 111 Fundamentals of Programming I Basic Program Elements.
Modules and Decomposition UW CSE 190p Summer 2012 download examples from the calendar.
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.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
INTRODUCTION TO MATLAB LAB# 01
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.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
Recap Function M-files Syntax of Function M-Files Comments Multiple Input and Output Functions.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 21.
Scientific Computing Introduction to Matlab Programming.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
MA/CS 375 Fall 2002 Lecture 3. Example 2 A is a matrix with 3 rows and 2 columns.
Getting Started with MATLAB (part 3) 1. Algebra, 2. Trig 3. The keyword ans 4. Clean up and suppress output: finalizing the software’s presentation 1.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
MATLAB Lecture Two Tuesday 5 July Chapter 3.
MA/CS 375 Fall 2002 Lecture Summary Week 1  Week 7.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Array Operations ENGR 1181 MATLAB 4.
STAT 534: Statistical Computing Hari Narayanan
PHY 107 – Programming For Science. Announcements  Lectures may not cover all material from readings  Material that is most difficult or challenging.
MA/CS 375 Fall 2003 Lecture 3. .* Multiplication We can use the.* operator to perform multiplication entry by entry of two matrices:
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.
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
Jake Blanchard University of Wisconsin Spring 2006.
MTH108 Business Math I Lecture 20.
Matlab Workshop Getting Started.
Matlab Training Session 4: Control, Flow and Functions
L – Modeling and Simulating Social Systems with MATLAB
Introduction to Programming for Mechanical Engineers (ME 319)
MATLAB DENC 2533 ECADD LAB 9.
User Defined Functions
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
Presentation transcript:

MA/CS 375 Fall 2002 Lecture 2

Motivation for Suffering All This Math and Stuff Try the Actor demo from

Office Hours I will be available: – 1:30pm to 3:00pm Tuesday and Thursdays –Room 435, Humanities Building

Attendance Checkpoints Reminder I will produce a sign up sheet 9 more times this semester Each sign in is worth 2 percent of your final grade

The Goal of 375 Introduce you all to the implementation, design of numerical methods. We will be using Matlab as our working platform. Very little existing math knowledge will be assumed, and any required will be introduced. Team work.

What is Matlab ? Matlab is a (mostly) text based math processing language:

Close Up of Command Window This is a text prompt, just like the one in Unix.

What Does Matlab Do ? Linear algebra (vectors, matrices…) Graph plotting Functions Much, much, much more. Check out:

How To Start Matlab Under windows: –Click on the “Start” menu button –Click on the “Matlab” menu entry –This should create a Matlab window. Alternatively on the UNM unix system: –telnet to aix.unm.edu –type matlab –a matlab prompt should appear

Example 1 a = 1 b = a/2 c = b*3 Do the math and: b = a/2 = ½ c = b*3 = 1.5

Close Up of Example 1 Notes if you end a line with ; then matlab does not print the result a, b and c are automatically created if you now change b, then c will NOT be automatically updated.

Example 2 A is a matrix with 3 rows and 2 columns.

Close Up of Example 2 A(2,1) = 4.12; says: set the entry of A in the 2 nd row and 1 st column to 4.12

Example 2 (in C) For those of you familiar with C, this is similar code (but not identical) –double A[3][2]; –A[0][0] = 2.1; –A[0][1] = 3.23; –A[1][0] = 4.12; –A[1][1] = 1.893; –A[2][0] = 7.1; –A[2][1] = 5.0;

Observations from Example 2 In Matlab you do not need to specify the type of the variables unlike C Matlab keeps track of the size of matrices. Beware – unlike C, Matlab stores data by column first (board explanation)

Example 2 Revisited A is a matrix with 3 rows and 2 columns. We can build A directly with the following:

Example 3 in C For those of you familiar with C, this is similar code (but not identical) –double A[3][2] = [[2.1,3.23],[4.12,1.893],[7.1,5.0]];

Vectors A vector is just a special case of a matrix. If you require a vector of length 3, then:

Alternative ways to build vectors

Alternative Ways to Build Vectors cont

Now What? So we have found a few different ways to build matrices (and vectors). Well – we can now do some matrix- vector algebra. The following operators are allowed: – +, -, *,.*, /, \

Adding Matrices Recall if I wish to add two matrices together: Where i’th row, j’th column

Matrix Addition in Index Notation

Matrix Addition in Matlab Random demo on the board, volunteers.

Notes on Matrix Addition If I want to add two matrices A and B then –the dimensions of A and B must be the same –i.e. # rows of A = # rows of B # columns of A = # columns of B what happens when we try to add to matrices of different dimensions in Matlab? Guesses?

Error Messages… Volunteer to explain why this is the case.

Matrix Subtraction in Matlab Random demo on the board, volunteers.

Result of Matrix Subtraction

Matrix Multiplication There is a specific definition of matrix multiplication. In index notation: i.e. for the (i,j) of the result matrix C we take the i’th row of A and multiply it, entry wise, with the j’th column of B

Example 4 (matrix multiplication) Volunteer?.

Result of Example 4

Matrix Division We will save the / and \ operators for later.

Functions in Matlab Matlab has a number of built-in functions: –cos, sin, tan, acos, asin, atan –cosh, sinh, tanh, acosh, asinh, atanh –exp, log, sqrt They all take matrices as arguments and return matrices of the same dimensions. e.g. cos([1 2 3]) For other functions type: > help matlab\elfun

Example of Function of Vector

Special Random Matrix Function Say I want to create a 3 by 2 matrix with random entries, with each entry between 0 and 1: What will happen if I run this again?

Customizing Matlab

Matlab is Yours to Command It is very likely that you will need to use the same string of commands, over and over. We can create a.m file which contains a set of commands which will be executed. – e.g. file create a file mygrid.m containing: x1d = linspace( 0, 1, Npts); y1d = linspace( 0, 1, Npts); [x2d, y2d] = meshgrid( x1d, y1d); show demo, including directory selection

Calling Your Own Script

Custom-Made Matlab Functions function [ radius, theta] = myfunc( x, y) % this is a comment, just like // in C++ % now create and evaluate theta (in radians) theta = atan2(y,x); % now create and evaluate radius radius = sqrt( x.^2 + y.^2); function end Say we wish to create a function that turns Cartesian coordinates into polar coordinates. We can create a text file with the following text. It can be called like any built in function.

Custom Built Function For Matlab Make sure you use cd in Matlab to change to the directory containing myfunc.m the arguments to myfunc could also have been matrices – leading to two matrices being output.

Constraints on Custom-Built Matlab Functions Matlab follows similar scope rules to C. Without resorting to the Matlab command global the only variables available inside the function are those passed as arguments to the function, or created inside the function. Just in case you are thinking about using global – I consider it poor programming…

Loops in Matlab

Much like C or Fortran we can use a loop syntax to repeat a sequence of commands. HOWEVER, Matlab is an interpreted language and as such is not efficient in executing loop operations. In other words, using loops in Matlab is very slow!.

Loops in Matlab One variant of Matlab loop syntax is: for var=start:end commands; end

Example of a Matlab Loop Say I want to add the numbers from 1 to 10, without using the Matlab intrinsic sum.

Summary of Lecture 2 We have learnt how to: – run matlab – create matrices (and hence vectors) – set the entries of a matrix – add two matrices – subtract two matrices – multiply two matrices – loops – creating custom functions..