CS112 Scientific Computation Department of Computer Science Wellesley College Cold Coffee Vectors and plotting.

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

7.7 Choosing the Best Model for Two-Variable Data p. 279.
EXAMPLE 1 Use a linear model Tuition The table shows the average tuition y (in dollars) for a private four-year college in the United States from 1995.
Exponents and Scientific Notation.
CS112 Scientific Computation Department of Computer Science Wellesley College Decisions, Decisions… Conditional statements and expressions.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Project Maths: Use of Casio Calculators
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Logarithmic and Exponential Functions
Chapter 1 Sections 1.3 & 1.4.
Computer Science 121 Scientific Computing Winter 2014 Chapter 3 Simple Types: Numbers, Text, Booleans.
How old are you. How tall are you
Energy is the capacity to do work. Physical changes such as boiling, freezing and evaporation involve energy changes. Chemical changes involve chemical.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
+ The Strength of Modeling in Science Focus: Energy in temperature changes and changes of state.
CS112 Scientific Computation Department of Computer Science Wellesley College Matrices Storing two-dimensional numerical data.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
6.4 Exponential Growth and Decay. What you’ll learn about Separable Differential Equations Law of Exponential Change Continuously Compounded Interest.
7-2 Graphing Exponential Functions
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
1 Yangon Technological University Department of Mechanical Engineering Computer Application In Mechanical Engineering I ME Dr. Yin Yin Tun Deputy.
CS112 Scientific Computation Department of Computer Science Wellesley College Hodgepodge “Clumsy mixture of ingredients…”
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Scientific Computing Introduction to Matlab Programming.
Variables Damian Gordon. Variables We know what a variable is from maths. We’ve all seen this sort of thing in algebra: 2x – 10 = 0 2x = 10 X = 5.
CS112 Scientific Computation Department of Computer Science Wellesley College Building your own Functions.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
ENG College of Engineering Engineering Education Innovation Center 1 More Script Files in MATLAB Script File I/O : Chapter 4 1.Global Variables.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
MATLAB – PT1 The purpose of this workshop is to get you started and to have fun with MATLAB! Let’s talk a little and decide on what we will be covering.
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
1-d Arrays & Plotting.
CS112 Scientific Computation Department of Computer Science Wellesley College Loops Iteration with for loops.
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
CS112 Scientific Computation Department of Computer Science Wellesley College Tables More matrix fun.
Finding an Exponential Regression Use the data in the program file COOL to find an exponential model.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
CS112 Scientific Computation Department of Computer Science Wellesley College Decisions, Decisions… Conditional statements and expressions.
Practical Programming COMP153-08S Arithmetic and Types.
CS112 Scientific Computation Department of Computer Science Wellesley College Storing Values for Safe Keeping Variables and their Values.
CS112 Scientific Computation Department of Computer Science Wellesley College Building your own Functions.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans.
Introduction to: Python and OpenSesame FOR PROS. OpenSesame In OpenSesame you can add Python in-line codes which enables complex experiment. We will go.
Right and Wrong Ways to Use your calculator on the AP Calc Exam
CS112 Scientific Computation Department of Computer Science Wellesley College Vectors and indexing Tools of the trade.
Lecture 11 Introduction to R and Accessing USGS Data from Web Services Jeffery S. Horsburgh Hydroinformatics Fall 2013 This work was funded by National.
Key Stage 3 National Strategy Session 1:What is modelling? Session 2:Teaching modelling at Key Stage 3 Session 3:Extending modelling in the classroom Modelling.
Department of Computer Science Western Michigan University
C++ Basics Lecture 2.
Algorithm & Flowchart.
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Python: Experiencing IDLE, writing simple programs
Input and Output Upsorn Praphamontripong CS 1110
Introduction to Scientific Method
Computing Fundamentals
Quiz minutes We will take our 5 minute break after all quizzes are turned in. For today’s lesson you do not need your text book , but you will.
“Clumsy mixture of ingredients…”
Cold Coffee Vectors and plotting
IDLE Hints To re-load a module after making changes:
7-4 Exponential Growth and Decay
CS1110 Today: collections.
Presentation transcript:

CS112 Scientific Computation Department of Computer Science Wellesley College Cold Coffee Vectors and plotting

Vectors3-2 Cold, funny-tasting coffee Time(min)Temperature (°C) :

Vectors3-3 Vectors ● A vector is an ordered collection of numbers times = [ ] temps = [ ] 93.5 temps times

Vectors3-4 Plotting data: Round 1 ● Create a 2D graph with the plot function times = [ ] temps = [ ] plot(times, temps) vector of x coordinates vector of y coordinates

Vectors3-5 Computations on collections of data ● Perform the same arithmetic operation on each element of vector >> times = [ ] >> times = 60 * times 0 times times

Vectors3-6 Time-out exercise ● Write an assignment statement to convert temperature from Celcius to Fahrenheit* >> temps = [ ] >>... * Hint: F = 32 + (9/5)C 93.5 temps temps

Vectors3-7 More vector magic ● Perform element-by-element computations on two vectors, e.g. average the two data samples* >> sample1 = [ ] >> sample2 = [ ] * Hint: How do you calculate the average of two single numbers sample1 and sample2? 3.2 sample sample

Vectors3-8 The envelope please ● Element-by-element average: >> sample1 = [ ] >> sample2 = [ ] >> average = (sample1 + sample2) / sample sample average

Vectors3-9 Let’s try that one again ● Perform element-by-element computations on two vectors, e.g. multiply corresponding values in the two data samples* >> sample1 = [ ] >> sample2 = [ ] 3.2 sample sample * oops…

Vectors3-10 Still more magic ● Compute a single value from the contents of a vector >> sample1 = [ ] >> totalSum = sum(sample1) >> totalProd = prod(sample1) >> sampleSize = length(sample1) >> minValue = min(sample1) >> maxvalue = max(sample1) >> avgValue = mean(sample1) 3.2 sample

Vectors3-11 Creating sequences ● Often you will want to create a sequence of evenly spaced numbers* ● Use colon notation >> nums = 1:2:9 * Trust me, you really will want to do this someday! startstep end 1 nums

Vectors3-12 Creating evenly spaced sequences ● Use the linspace function: linspace(start, end, num) to create a vector of num evenly spaced numbers from start to end >> nums = linspace(0, 10, 5) 0.0 nums * Write an assignment statement that stores a sequence of 5000 evenly spaced numbers from 1 to 1000

Vectors3-13 Plotting data: Round 2 ● Adjust the appearance of lines and markers with a third input to the plot function: plot(times,temps,‘g--*’); ● Third input is a string of 1 to 4 characters in single quotes: color: b g r c m y k w marker:. o x + * s d v ^ p h linestyle: - : ● Add text labels: xlabel(‘Time, minutes’) ylabel(‘Temperature, Celcius’) title(‘Cooling a Cup of Coffee’)

Vectors3-14 Newton’s Law of Cooling ● An object’s rate of cooling depends on the difference between object’s temperature and ambient temperature ● Temperature decreases exponentially over time ● According to Newton: T(t) = T env + (T(0) - T env )e -kt where T(t) is object temperature at time t T(0) is initial temperature of object T env is environment temperature k depends on material (for coffee k ~ )

Vectors3-15 Coffee break % cooling.m % compares the direct measurement of cooling of coffee with % the cooling rate predicted by Newton’s Law of Cooling timeData = [ ]; tempData = [ ]; plot(timeData, tempData, ‘b-*’) xlabel(‘Time, minutes’) ylabel(‘Temperature, degrees Celcius’) title(‘Cooling a Cup of Coffee’) timeSamples = 0:5:200; tempLaw = * exp( * timeSamples); hold on plot(timeSamples, tempLaw, ‘g--o’) hold off

Vectors3-16 Ta Da!

Vectors3-17 Exercise: Center of Mass % coordinates and masses of particles xcoords = [ ]; ycoords = [ ]; masses = [ ]; % calculate the center of mass of the particles xcenter = ycenter = % print center of mass coordinates using disp