12
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING

CS 170 – Intro to Scientific and engineering Programming

  • Upload
    snana

  • View
    31

  • Download
    0

Embed Size (px)

DESCRIPTION

CS 170 – Intro to Scientific and engineering Programming . Cold coffee. An experiment. Time(min) Temperature (°C) 0 93.5 1 90.6 2 87.7 3:30 83.9 7 76.6 10 71.3 18 61.5 26 65.8 34 49.2 52 41.9 113 29.1 166 25.5 191 25.0. - PowerPoint PPT Presentation

Citation preview

Page 1: CS 170 – Intro to Scientific  and engineering Programming

CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING

Page 2: CS 170 – Intro to Scientific  and engineering Programming

Cold coffee

Page 3: CS 170 – Intro to Scientific  and engineering Programming

An experimentTime(min) Temperature (°C)

0 93.51 90.62 87.73:30 83.97 76.610 71.318 61.526 65.834 49.252 41.9113 29.1166 25.5191 25.0

Page 4: CS 170 – Intro to Scientific  and engineering Programming

Plotting data: Round 1times = [0 1 2 3.5 7]temps = [93.5 90.6 87.7 83.9 76.6]

plot(times, temps)

Page 5: CS 170 – Intro to Scientific  and engineering Programming

Exercise• Help your poor Greek professor!

Write an assignment statement to convert temperature from Celcius to Fahrenheit*

*Hint: F = 32 + (9/5)C

Page 6: CS 170 – Intro to Scientific  and engineering Programming

Element by element>> sample1 = [3.2 1.1 4.7 2.1 6.2]>> sample2 = [3.0 1.2 4.4 2.4 6.1]>> average = (sample1 + sample2) / 2

How about multiplication?

Page 7: CS 170 – Intro to Scientific  and engineering Programming

SequencesUse colon notation>> nums = 1:2:9

Use the linspace function:linspace(start, end, num)

Page 8: CS 170 – Intro to Scientific  and engineering Programming

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’)

Page 9: CS 170 – Intro to Scientific  and engineering Programming

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) = Tenv + (T(0) - Tenv)e-kt

whereT(t) is object temperature at time tT(0) is initial temperature of objectTenv is environment temperaturek depends on material (for coffee k ~ 0.0426)

Page 10: CS 170 – Intro to Scientific  and engineering Programming

Coffee Break!

Page 11: CS 170 – Intro to Scientific  and engineering Programming

QUESTIONS??

Page 12: CS 170 – Intro to Scientific  and engineering Programming

Resources• Lecture slides CS112, Ellen Hildreth,

http://cs.wellesley.edu/~cs112/