HMC’s Galileo Auditorium Some of Cope’s generated MP3s:

Slides:



Advertisements
Similar presentations
1 Convert this problem into our standard form: Minimize 3 x x 2 – 6 x 3 subject to 1 x x 2 – 3 x 3 ≥ x x 2 – 6 x 3 ≤ 5 7 x 1.
Advertisements

CS 177 Recitation Week 8 – Methods. Questions? Announcements  Project 3 milestone due next Thursday 10/22 9pm  Turn in with: turnin –c cs177=xxxx –p.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 8 Multidimensional.
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
Lecture 16: Big-Oh Notation
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
What's ahead? Conway gives a whole new outlook on "loopy" ! John Conway 10/18 no class - Fall break 10/19 no new hw due 10/11 Dynamic & binary data 10/12.
The not-so-subtle art of singling out the best (and worst) of anything… Computing with language Computing to the max You know this would make me hungry…
CS 5 Today HW 9 (lab + 2 probs) due Sunday, 11/8 at midnight Dizzying arrays of possibilities… John Conway Carl Gauss This week’s credits: Exam 2 on Mon.,Tue.
CSC Intro. to Computing Lecture 13: PALGO. Announcements Midterm is in one week  Time to start reviewing  We will do more review in class Tuesday.
Homework 3 Due ( MT sections ) ( WTh sections ) at midnight Sun., 9/21 Mon., 9/22 Problems
The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies.
Topic 26 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable.
EECS 110: Lec 12: Mutable Data Aleksandar Kuzmanovic Northwestern University
This week in CS 5 HW 9 (2 problems) M/T sections W/Th sections due Sunday, 11/4 at midnight due Monday, 11/5 at midnight Recitation for HW9 -- Friday 11/2.
Homework 9 Due ( M & T sections ) ( W & Th sections ) at midnight Sun., 11/3 Mon., 11/4 Problems
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Homework 8 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/28 Mon., 10/29 Problems Reading is under week 7, however.
Code Compression the benefits of looping... Today in CS 5 HW 4 - (3 problems) M/T sections W/Th sections due Sunday, 9/26 at midnight due Monday, 9/27.
Ionut Trestian Northwestern University
Week 12 - Wednesday.  What did we talk about last time?  Hunters and prey.
LECTURE 23: LOVE THE BIG-OH CSC 212 – Data Structures.
Identifying Old Stars. Here’s What I Claimed As sun-like stars run out of Hydrogen in the core, they swell up into red giants. Question: do you believe.
EECS 110: Lec 12: Mutable Data Aleksandar Kuzmanovic Northwestern University
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Lecture 2 Review of 1301 and C# Richard Gesick. Common data types int, long, double, float, char, bool, string.
Cs205: engineering software university of virginia fall 2006 Programming Exceptionally David Evans
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Department of Computer Science Western Michigan University
EECS 110: Lec 12: Mutable Data
User-Written Functions
EGR 2261 Unit 10 Two-dimensional Arrays
CS1020 – Data Structures And Algorithms 1 AY Semester 2
Two-Dimensional Arrays
Loops BIS1523 – Lecture 10.
COSC 220 Computer Science II
Week 9 - Monday CS 121.
Java Software Structures: John Lewis & Joseph Chase
Each column represents another power of the base
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Introduction to Programming
CSC 113 Tutorial QUIZ I.
More Loop Examples Functions and Parameters
Conditions and Ifs BIS1523 – Lecture 8.
Introduction to Programming
Topic 26 Two Dimensional Arrays
Numbers and their bases
Ionut Trestian Northwestern University
CS 201 Fundamental Structures of Computer Science
More 2 D Array.
2D Array and Matrix.
Two-Dimensional Arrays
CISC124 Labs start this week in JEFF 155. Fall 2018
Searching, Sorting, and Asymptotic Complexity
Multidimensional Arrays
CSE 373: Data Structures & Algorithms
Computer Architecture and Assembly Language
Why did the programmer quit his job?
Lesson #6 Modular Programming and Functions.
EECE.2160 ECE Application Programming
Hank Childs, University of Oregon
Northwestern University
Functions continued.
Modeling Pattern Formation in Skin Diseases by a Cellular Automaton
Introduction to Computer Science I.
ECE 352 Digital System Fundamentals
EECS 110: Lec 12: Mutable Data
More 2D Array and Loop Examples Functions and Parameters
2D Array and Matrix Application: Game of Life
Week 7 - Monday CS 121.
Presentation transcript:

HMC’s Galileo Auditorium Some of Cope’s generated MP3s: Experiments in Musical Intelligence I began Experiments in Musical Intelligence in 1981 as the result of a composer's block. My initial idea involved creating a computer program which would have a sense of my overall musical style and the ability to track the ideas of a current work such that at any given point I could request a next note, next measure, next ten measures, and so on. My hope was that this new music would not just be interesting but relevant to my style and to my current work. Having very little information about my style, however, I began creating computer programs which composed complete works in the styles of various classical composers, about which I felt I knew something more concrete. Since the early days of Experiments in Musical Intelligence, many audiences have heard its output in the styles of classical composers. The works have delighted, angered, provoked, and terrified those who have heard them. I do not believe that the composers and audiences of the future will have the same reactions. Ultimately, the computer is just a tool with which we extend our minds. The music our algorithms compose are just as much ours as the music created by the greatest of our personal human inspirations. Nelson Series Talk Wed, 10/27 7:00 pm HMC’s Galileo Auditorium Some of Cope’s generated MP3s: arts.ucsc.edu/faculty/cope/mp3page.htm David Cope, UC Santa Cruz

Still seeking a costume? Week 9 in CS 5 Lab: M-Z A dizzying array of possibilities… HW 9 (2 probs) due Sunday, 10/31 at midnight M/T due Monday, 11/1 at midnight W/Th Reading: Week 9’s online notes Recitation for HW9 -- Friday 10/29 This week’s credits: John Conway Still seeking a costume? Carl Gauss

“Pass By Value” 7 public static void main(String[] args) { H.pl(“Welcome to Conformity, Inc.”); int fav = 7; // The user’s favorite # conform(fav); H.pl(fav + “ is my favorite, too!”); } public static void conform(int fav) fav = 42; return; 7 int fav int fav

“Pass by value” means that data is copied when sent to a method public static void main(String[] args) { H.pl(“Welcome to Conformity, Inc.”); int fav = 7; // The user’s favorite # conform(fav); H.pl(fav + “ is my favorite, too!”); } public static void conform(int fav) fav = 42; return; 7 int fav PASS BY VALUE 7 42 int fav “Pass by value” means that data is copied when sent to a method

Passing Arrays by Value public static void main(String[] args) { H.pl(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.pl(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav[0] = 42; fav[1] = 42; return; int[] fav fav[0] fav[1] int[] fav

Passing Arrays by Value public static void main(String[] args) { H.pl(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.pl(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav[0] = 42; fav[1] = 42; return; int[] fav fav[0] fav[1] can change data elsewhere! int[] fav

Views of the world

Views of the world Engineers think their equations are an approximation to reality.

Views of the world Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations.

Views of the world Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care. 

Creating structure from a few simple facts... Views of the world Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care.  Creating structure from a few simple facts... ? Axioms Definitions 20˚ 10˚ 60˚ Proof 70˚

The John Conway Challenge…. ? 20˚ 10˚ 60˚ 70˚ (without using trig)

Views of the world Proof Algorithm Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care.  Creating structure from a few simple actions ... Creating structure from a few simple facts... for arrays variables Axioms while Definitions arithmetic operations if/else Proof Algorithm

they don’t have to be horizontal lists! Arrays’ flexibility Arrays can be of ANY type double[] A; 42.0 75.0 70.0 A = new double[3]; double[] double double double A they don’t have to be horizontal lists!

they don’t have to be horizontal lists! Arrays’ flexibility Arrays can be of ANY type double[] A; 42.0 75.0 70.0 A = new double[3]; double[] double double double A 42.0 double[] double they don’t have to be horizontal lists! A 75.0 double 70.0 double

Arrays’ flexibility Arrays can be of ANY type double[] A; int[] A; 42.0 75.0 70.0 A = new double[3]; double[] double double double A int[] A; 42 7 -11 A = new int[3]; int[] int int int A String[] A; “go” “red” “sox!” A = new String[3]; String[] String String String A

2d arrays Arrays can be of ANY type -- so what type of array is A ? double[][] A; double[][] A

A is an array of double arrays! 2d arrays Arrays can be of ANY type -- even other arrays! double[][] A; A is an array of double arrays! double[][] A

2d arrays Arrays can be of ANY type -- even other arrays! double[][] A; A = new double[3][]; double[] double[][] A[0] A double[] A[1] double[] A[2]

Jagged arrays Rows of 2d arrays need not be the same length! double[][] A; A = new double[3][]; double[] double[][] A[0] double double double double A double[] A[1] double double double[] A[2] double double double double double A[0] = new double[4]; A[1] = new double[2]; A[2] = new double[5];

We will not use jagged arrays Rows of 2d arrays need not be the same length! double[][] A; A = new double[3][]; double[] double[][] A[0] double double double double A double[] A[1] double double double[] A[2] double double double double double A[0] = new double[4]; A[1] = new double[2]; A[2] = new double[5];

Rectangular arrays But there’s a shortcut to creating them if they are... double[][] A; rows cols A = new double[3][4]; double[] double[][] double double double double A[0] A double[] double double double double A[1] double[] A[2] double double double double

double[][] A = new double[3][4]; 2d arrays Getting at individual elements: rows cols double[][] A = new double[3][4]; double[] double[][] double double double double A[0] A A[0][0] double[] double double double double A[1] double[] A[2] double double double double A[2][3] A[1][2] = 10.0

these will be variables 2d arrays: Input public static void main(String[] args) { double[][] A = new double[3][4]; H.pl(“Input your values:”) for (int r=0 ; r<3 ; ++r) for (int c=0 ; c<4 ; ++c) A[r][c] = H.nd(); } these will be variables no i or j ?

how do we find the number of rows and the number of columns? 2d arrays: Input Method public static void enterValues(double[][] A) { H.pl(“Input your values:”); for (int r=0 ; r < ; ++r) for (int c=0 ; c < ; ++c) A[r][c] = H.nd(); } how do we find the number of rows and the number of columns? number of rows number of columns

number of columns in row r 2d arrays: Output public static void print(double[][] A) { for (int r = 0; r < A.length; ++r) for (int c = 0; c < A[r].length; ++c) H.p( } number of rows number of columns in row r I/O formatting reference: http://www.cs.hmc.edu/courses/2004/fall/cs5/HMCSupport.html

Problem 1 An array of array handlers... Initial Setup Menu Methods Get the number of rows and columns Create an array of the appropriate number of elements (doubles). Get initial values from the user into the array. printMenu enterValues print multRow addRowaIntoRowb addMxRowaIntoRowb solve Menu (0) Change the values in the array (1) Print the array (2) Multiply an array row (3) Add one row to another (4) Add a multiple of one row to another (5) Solve! (9) Quit Which choice would you like? Methods

What are the resulting values in A? Before “Quiz” 1 2 3 4 5 6 7 8 9 10 11 12 row 0 Starting with the 2d array A shown here, what are the values in A after running this code? row 1 row 2 col 0 col 1 col 2 col 3 public static void mysteryMethod(int[][] A) { for (int r = 0 ; r < A.length ; ++r) for (int c = 0 ; c < A[r].length ; ++c) if (r == c) A[r][c] = 42; } else A[r][c] = A[r][c] + 1; } // end of mystery method A After What are the resulting values in A?

“Quiz” A A example before example after 0.00 1.00 0.00 1.00 row 0 0.00 1.00 0.00 1.00 3.00 0.50 0.50 3.00 10.00 20.00 30.00 40.00 Write a method that adds two times the values in row #1 into the values in row #2. The values in row #1 should not change! (The values in row #0 also don’t change!) row 1 two of row 1 are to be added to row 2 row 2 row 0 0.00 1.00 0.00 1.00 3.00 0.50 0.50 3.00 16.00 21.00 31.00 46.00 row 1 row 2 A example after public static void addTwoOfRow1IntoRow2(double[][] A) { }

Adding one row to another... Before A After 2.00 3.00 -1.00 -8.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 2.00 3.00 -1.00 -8.00 -3.00 -1.00 2.00 42.00 3.00 -6.00 3.00 48.00 public static void addRowaIntoRowb(double[][] A, int ra, int rb) { }

Adding one row to another... Before A After 2.00 3.00 -1.00 -8.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 2.00 3.00 -1.00 -8.00 -3.00 -1.00 2.00 42.00 3.00 -6.00 3.00 48.00 2 public static void addRowaIntoRowb(double[][] A, int ra, int rb) { }

Problem 1 An array of array handlers... Initial Setup Menu Methods Get the number of rows and columns Create an array of the appropriate number of elements (doubles). Get initial values from the user into the array. printMenu enterValues print multRow addRowaIntoRowb addMxRowaIntoRowb solve Menu (0) Change the values in the array (1) Print the array (2) Multiply an array row (3) Add one row to another (4) Add a multiple of one row to another (5) Solve! (9) Quit Which choice would you like? Methods

Gaussian Elimination Goal: Find p,n,q 2p + 3n + -1q = -8.00 Carl Gauss is so money! 2p + 3n + -1q = -8.00 -3p + -1n + 2q = 42.00 1p + -9n + 4q = 56.00 Goal: Find p,n,q

Gaussian Elimination Goal: get 1s along the diagonal Find p,n,q get 0s elsewhere on the left 1p + 0n + 0q = 1.00 0p + 1n + 0q = 5.00 0p + 0n + 1q = 25.00

Gaussian Elimination Goal: get 1s along the diagonal Find p,n,q Carl Gauss is money. 2p + 3n + -1q = -8.00 -3p + -1n + 2q = 42.00 1p + -9n + 4q = 56.00 get 1s along the diagonal Goal: Find p,n,q get 0s elsewhere on the left 1p + 0n + 0q = 1.00 0p + 1n + 0q = 5.00 0p + 0n + 1q = 25.00 Using only row operations (our methods) ! Just the array is necessary ! We can get rid of the variables... where to start?

Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5

a hint as to the direction to head next… ! Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5 a hint as to the direction to head next… !

add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5 1.00 1.50 -0.50 -4.00 0.00 3.50 0.50 30.00 0.00 -10.50 4.50 44.00 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2

add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5 1.00 1.50 -0.50 -4.00 0.00 3.50 0.50 30.00 0.00 -10.50 4.50 44.00 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 1.00 0.00 -0.71 -16.85 0.00 1.00 0.14 30.00 0.00 0.00 6.00 150.00 add a multiple of Row 1 to Row 0 multiply Row 1 by 1/3.5 add a multiple of Row 1 to Row 2

add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5 1.00 1.50 -0.50 -4.00 0.00 3.50 0.50 30.00 0.00 -10.50 4.50 44.00 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 1.00 0.00 -0.71 -16.85 0.00 1.00 0.14 30.00 0.00 0.00 6.00 150.00 add a multiple of Row 1 to Row 0 multiply Row 1 by 1/3.5 add a multiple of Row 1 to Row 2 1.00 0.00 0.00 1.00 0.00 1.00 0.00 5.00 0.00 0.00 1.00 25.00 same for other columns and so on...

Problem 2 -- “Life” Grid World black cells are alive John Conway Grid World black cells are alive Evolutionary rules Everything depends on a cell’s eight neighbors Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) white cells are empty

Problem 2 -- Life Grid World black cells are alive Evolutionary rules Everything depends on a cell’s eight neighbors Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) white cells are empty

Problem 2 -- Life Grid World black cells are alive Evolutionary rules Everything depends on a cell’s eight neighbors Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) white cells are empty

Problem 2 -- Life Grid World Pair Program black cells are alive Evolutionary rules Everything depends on a cell’s eight neighbors Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) Keep going! white cells are empty life out there...

Problem 2 -- Creating Life update(int[][] last, int[][] next) new generation old generation 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5

Problem 2 -- Creating Life update(int[][] last, int[][] next) new generation old generation 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5

Problem 2 -- Details update(int[][] last, int[][] next) new generation old generation For each generation… 0 represents an empty cell 1 represents a living cell outermost edge should always be left empty (even if there are 3 neighbors) compute all cells based on their previous neighbors before updating any of them http://www.math.com/students/wonders/life/life.html

Problem 2 -- Details What will this do? public static void update(int[][] last, int[][] next) { for (int r=1 ; r<last.length-1 ; ++r) for (int c=1 ; c<last[r].length-1 ; ++c) int oldvalue = last[r][c]; if (oldvalue == 0) // look at last next[r][c] = 1; // assign to next else next[r][c] = 0; }

How does this change things? Problem 2 -- Details How does this change things? public static void update(int[][] last, int[][] next) { for (int r=1 ; r<last.length-1 ; ++r) for (int c=1 ; c<last[r].length-1 ; ++c) int oldvalue = last[r-1][c-1]; if (oldvalue == 0) next[r][c] = 1; else next[r][c] = 0; }

Problem 2 – Multi-species Life (!) updateMulti(int[][] last, int[][] next) Create a set of rules to evolve two species of cells (plus empty). The Challenge Give both species a good chance of survival in the same environment. more species are OK, too… 1 2 … stability is an open biological question…

Lab this week Lab: M-Z Problem 1: Gaussian Elimination printMenu enterValues print multRow addRowaToRowb addMxRowaToRowb solve You’ll need to write (and use) Problem 2: Life and Multi-species Life! 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5 public void update(int[][] last, int[][] next) public void updateMulti(int[][] last, int[][] next) A matrix-inverse feature for Problem 1 ... Extra Credit: Doughnut Life for Problem 2 …

What are the resulting values in A? Before “Quiz” 1 2 3 4 5 6 7 8 9 10 11 12 row 0 Starting with the 2d array A shown here, what are the values in A after running this code? row 1 row 2 col 0 col 1 col 2 col 3 public static void mysteryMethod(int[][] A) { for (int r = 0 ; r < A.length ; ++r) for (int c = 0 ; c < A[r].length ; ++c) if (r == c) A[r][c] = 42; } else A[r][c] = A[r][c] + 1; } // end of mystery method A After What are the resulting values in A?

“Quiz” A A example before example after 0.00 1.00 0.00 1.00 row 0 0.00 1.00 0.00 1.00 3.00 0.50 0.50 3.00 10.00 20.00 30.00 40.00 Write a method that adds two times the values in row #1 into the values in row #2. The values in row #1 should not change! (The values in row #0 also don’t change!) row 1 two of row 1 are to be added to row 2 row 2 row 0 0.00 1.00 0.00 1.00 3.00 0.50 0.50 3.00 16.00 21.00 31.00 46.00 row 1 row 2 A example after public static void addTwoOfRow1IntoRow2(double[][] A) { }

Watch out! public static void main(String[] args) { H.out.println(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.out.println(fav + “ and ” + fav + “! Me too!”); } int[] fav fav[0] fav[1] What will happen here?!

Watch out! public static void main(String[] args) { H.out.println(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.out.println(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav = new int[2]; fav[0] = 42; fav[1] = 42; return; int[] fav fav[0] fav[1] int[] fav

Still seeking a costume? This week in IS 313 A dizzying array of possibilities... HW 7 (2 problems) due Thursday, 11/7 at midnight Reading: Week 9’s online notes This week’s credits: John Conway Still seeking a costume? Carl Gauss

Survival of the stablest http://www.math.com/students/wonders/life/life.html The Questions of Life... what are stable “life” forms? how densely can they grow? can they be unbounded spatially? how fast can they travel? can they grow forever?

“Pass By Value” public static void main(String[] args) { H.out.println(“Welcome to Conformity, Inc.”); int fav = 7; // The user’s favorite # conform(fav); H.out.println(fav + “ is my favorite, too!”); }

42 -100.1 3.14159 7 42 -100.1 3.14 7 42.00 -100.10 3.14 7.00 42.00 -100.10 3.14 7.00 42.00 -100.10 3.14 7.00

int age

A method for multiplying columns: Using 2d arrays arr 2.00 3.00 -1.00 -8.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 Before arr 2.00 3.00 -3.00 -8.00 -3.00 -1.00 6.00 42.00 1.00 -9.00 12.00 56.00 After A method for multiplying columns: MONUMENTAL COLUMNS HANDLED MONUMENTALLY WELL. The eight massive Corinthian columns at the National Building Museum in Washington, D.C., are among the largest interior columns in the world: 75 ft. high and 8 ft. in dia., the columns have a brick core (over 70,000 bricks each!) covered with stucco.

Solving ?! Gaussian Elimination Goal: get 1s along the diagonal 2p + 3n + -1q = -8.00 -3p + -1n + 2q = 42.00 1p + -9n + 4q = 56.00 Gaussian Elimination get 1s along the diagonal Goal: Find p,n,q get 0s elsewhere on the left 1.00p + 1.50n + -0.50q = -4.00 -3.00p + -1.00n + 2.00q = 42.00 1.00p + -9.00n + 4.00q = 56.00 multiply the zeroth row (R0) by 0.5 1.00p + 1.50n + -0.50q = -4.00 0.00p + 3.50n + 0.50q = 30.00 -0.00p + -10.50n + 4.50q = 44.00 add 3 times R0 to R1 add -1 times R0 to R2

Solved ! 1.00p + 1.50n + -0.50q = -4.00 0.00p + 3.50n + 0.50q = 30.00 multiply R1 by 1 / 3.5 1.00p + 1.50n + -0.50q = -4.00 0.00p + 1.00n + 0.14q = 8.57 -0.00p + -10.50n + 4.50q = 44.00 add -1.5 times R1 to R0 add 10.5 times R1 to R2 1.00p + 0.00n + -0.71q = -16.85 0.00p + 1.00n + 0.14q = 30.00 -0.00p + 0.00n + 6.00q = 150.00 add 3 times R0 to R1 add -1 times R0 to R2 continue... 1.00p + 0.00n + 0.00q = 1.00 0.00p + 1.00n + 0.00q = 5.00 -0.00p + 0.00n + 1.00q = 25.00 only the array is necessary !

Solved ! 1.00p + 1.50n + -0.50q = -4.00 0.00p + 3.50n + 0.50q = 30.00 multiply R1 by 1 / 3.5 1.00p + 1.50n + -0.50q = -4.00 0.00p + 1.00n + 0.14q = 8.57 -0.00p + -10.50n + 4.50q = 44.00 add -1.5 times R1 to R0 add 10.5 times R1 to R2 1.00p + 0.00n + -0.71q = -16.85 0.00p + 1.00n + 0.14q = 30.00 -0.00p + 0.00n + 6.00q = 150.00 add 3 times R0 to R1 add -1 times R0 to R2 continue... 1.00p + 0.00n + 0.00q = 1.00 0.00p + 1.00n + 0.00q = 5.00 -0.00p + 0.00n + 1.00q = 25.00 only the array is necessary !

Still seeking a costume? This week in IS 313 A dizzying array of possibilities... HW 7 (2 problems) due Thursday, 11/8 at midnight Reading: Week 9’s online notes Also: threads and Life ! John Conway Still seeking a costume? Carl Gauss

“Pass by value” means that data is copied when sent to a method public static void main(String[] args) { H.out.println(“Welcome to Conformity, Inc.”); int fav = 7; // The user’s favorite # conform(fav); H.out.println(fav + “ is my favorite, too!”); } public static void conform(int fav) fav = 42; 7 int fav PASS BY VALUE 7 42 int fav “Pass by value” means that data is copied when sent to a method

Passing Arrays by Value public static void main(String[] args) { H.out.println(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.out.println(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav[0] = 42; fav[1] = 42; return;

Watch out! public static void main(String[] args) { H.out.println(“Welcome to conformity, inc.”); int[] fav = new int[2]; fav[0] = 7; fav[1] = 11; // The user’s TWO favorite #s conform(fav); H.out.println(fav[0] + “ and ” + fav[1] + “! Me too!”); } public static void conform(int[] fav) fav = new int[2]; fav[0] = 42; fav[1] = 42; return;

Creating structure from a few simple facts... Views of the world Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care.  Creating structure from a few simple facts... ? Axioms Definitions 20˚ 10˚ 60˚ Proof 70˚

Views of the world Proof Algorithm Engineers think their equations are an approximation to reality. Physicists think reality is an approximation to their equations. Mathematicians don't care.  Creating structure from a few simple actions... Creating structure from a few simple facts... for arrays variables Axioms while Definitions arithmetic operations if/else Proof Algorithm

Jagged arrays Rows of 2d arrays need not be the same length! double[][] arr; arr = new double[3][]; arr[0] = new double[4]; arr[1] = new double[2]; arr[2] = new double[5]; double[] double[][] double double double double arr[0] arr double[] double double arr[1] double[] arr[2] double double double double double

Rectangular arrays But there’s a shortcut to creating them if they are... double[][] arr; arr = new double[3][4]; double[] double[][] double double double double arr[0] arr double[] double double double double arr[1] double[] arr[2] double double double double

more likely to be variables 2d arrays: Input public static void main(String[] args) { double[][] arr = new int[3][4]; for (int r=0 ; r<3 ; ++r) for (int c=0 ; c<4 ; ++c) arr[r][c] = H.in.nextDouble(); } more likely to be variables no i or j ?

how do we find the number of rows and the number of columns? 2d arrays: Input Method public static void enterArray(double[][] arr) { for (int r=0 ; r < ; ++r) for (int c=0 ; c < ; ++c) arr[r][c] = H.in.nextDouble(); } how do we find the number of rows and the number of columns? number of rows number of columns

Problem 1 An array of array handlers... Initial Setup Menu Methods Get the number of rows and columns Create an array of the appropriate number of elements (doubles). Get initial values from the user into the array. printMenu enterArray printArray multRow addR1ToR2 addMR1ToR2 solve Menu (0) Change the values in the array (1) Print the array (2) Multiply an array row (3) Add one row to another (4) Add a multiple of one row to another (5) Solve! (9) Quit Which choice would you like? Methods

Adding one row to another... arr Before arr After 2.00 3.00 -1.00 -8.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 2.00 3.00 -1.00 -8.00 -3.00 -1.00 2.00 42.00 3.00 -6.00 3.00 48.00 public static void addR1ToR2(double[][] arr, int rFrom, int rTo) { }

Only the array is necessary ! We can get rid of the variables... Gaussian Elimination Carl Gauss is so money! 2p + 3n + -1q = -8.00 -3p + -1n + 2q = 42.00 1p + -9n + 4q = 56.00 get 1s along the diagonal Goal: Find p,n,q get 0s elsewhere on the left 1p + 0n + 0q = 1.00 0p + 1n + 0q = 5.00 0p + 0n + 1q = 25.00 2.00 3.00 -1.00 -8.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 Only the array is necessary ! We can get rid of the variables...

add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 Solve 1.00 1.50 -0.50 -4.00 -3.00 -1.00 2.00 42.00 1.00 -9.00 4.00 56.00 multiply Row 0 by 0.5 1.00 1.50 -0.50 -4.00 0.00 3.50 0.50 30.00 0.00 -10.50 4.50 44.00 add 3 times Row 0 to Row 1 add -1 times Row 0 to Row 2 1.00 0.00 -0.71 -16.85 0.00 1.00 0.14 30.00 0.00 0.00 6.00 150.00 repeat for column 2 1.00 0.00 0.00 1.00 0.00 1.00 0.00 5.00 0.00 0.00 1.00 25.00 and column 3 and so on...

Problem 2 -- “Life” Grid World black cells are alive John Conway Grid World black cells are alive Evolutionary rules Everything depends on one’s eight neighbors Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) white cells are empty

Problem 2 -- Life Grid World black cells are alive Evolutionary rules Everything depends on one’s eight neighbors Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) white cells are empty

Problem 2 -- Life Grid World black cells are alive Evolutionary rules Everything depends on one’s eight neighbors Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) white cells are empty

Problem 2 -- Life Grid World black cells are alive Evolutionary rules Everything depends on one’s eight neighbors Exactly 3 neighbors give birth to a new, live cell! Exactly 2 or 3 neighbors keep an existing cell alive Any other number of neighbors kill the central cell (or keep it dead) Keep going! white cells are empty life out there...

Problem 2 -- Creating Life public void update(int[][] last, int[][] next) new generation old generation 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5

Problem 2 -- Creating Life public void update(int[][] last, int[][] next) new generation old generation 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5

Problem 2 -- Details public void update(int[][] last, int[][] next) new generation old generation For each generation… 0 represents an empty cell 1 represents a living cell outermost edge should always be empty (even if there are 3 neighbors) compute all cells based on their previous neighbors before updating any of them http://www.math.com/students/wonders/life/life.html