CSCE 121:509-512 Introduction to Program Design and Concepts, Honors J. Michael Moore Spring 2015 Set 14: Plotting Functions and Data 1.

Slides:



Advertisements
Similar presentations
Arithmetic Calculations
Advertisements

Chapter 15 Functions and graphing Bjarne Stroustrup
Chapter 8 Technicalities: Functions, etc. Bjarne Stroustrup
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
Methods Java 5.1 A quick overview of methods
An Introduction to Verilog-A: Transitioning from Verilog
Chapter 15 Functions and graphing John Keyser’s Modification of Slides by Bjarne Stroustrup
Setting the PYTHONPATH PYTHONPATH is where Python looks for modules it is told to import List of paths Add new path to the end with: setenv PYTHONPATH.
Perkovic, Chapter 7 Functions revisited Python Namespaces
Chapter Five Functions
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Lecture 5.
Functions. COMP104 Functions / Slide 2 Introduction to Functions * A complex problem is often easier to solve by dividing it into several smaller parts,
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 13 Fall 2010.
Excel Notes Phys244/246 © 2007, B.J. Lieb. Calculating Velocity The velocity is calculated by entering the following: =(B3-B2) / (A3-A2). Then drag the.
BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
Chapter 15 Functions and Graphing
Tcl and Otcl Tutorial Part I Internet Computing KUT Youn-Hee Han.
Concepts when Python retrieves a variable’s value Namespaces – Namespaces store information about identifiers and the values to which they are bound –
Function (L16) * Mathematical Library Functions * Program Components in C++ * Motivations for Functionalizing a Program * Function Prototype * Function.
BIL101, Introduction to Computers and Information Systems Chapter 12 A Portable Scientific Visualization Program: GnuPlot Prepared by Metin Demiralp Istanbul.
FORTRAN.  Fortran or FORmula TRANslation was developed in the 1950's by IBM as an alternative to Assembly Language. First successfull high level language.
EGR 105 Foundations of Engineering I Session 3 Excel – Basics through Graphing Fall 2008.
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.
1 Data types, operations, and expressions Continued l Overview l Assignment statement l Increment and Decrement operators l Short hand operators l The.
CS1313: Standard Library Functions Lesson CS1313 Spring Standard Library Functions Outline 1.Standard Library Functions Outline 2.Functions in Mathematics.
1 CS101 Introduction to Computing Lecture 35 Mathematical Methods (Web Development Lecture 12)
Computer Science 121 Scientific Computing Winter 2014 Chapter 3 Simple Types: Numbers, Text, Booleans.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
CSC 110 Numeric data types [Reading: chapter 3] CSC 110 D 1.
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.
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) MATH Functions in C Language.
Math 15 Lecture 7 University of California, Merced Scilab A “Very” Short Introduction.
Computer Science 111 Fundamentals of Programming I Basic Program Elements.
Modules and Decomposition UW CSE 190p Summer 2012 download examples from the calendar.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 3: Objects, Types, and Values 1 Based on slides.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Victor Kuliamin Institute for System Programming, Russian Academy of Sciences Moscow.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
1 MatLab Basics Jae Hoon Kim Department of Physics Kangwon National University It contains hundreds of commands to do mathematics. Graph functions, solve.
CSCE 121: Introduction to Program Design and Concepts Dr. J. Michael Moore Spring 2015 Set 12: A Display Model 1 Based on slides created by Bjarne.
Plane Curves and Parametric Equations New Ways to Describe Curves (10.4)
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with.
Chapter 15 Functions and graphing Bjarne Stroustrup
Calculations Chapter Twelve. More serious than Chapter Four Page 199 some sizes (in bytes) of various primititive types: Do Not Memorize typeSize(bits)Approx.
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Slide Copyright © 2012 Pearson Education, Inc.
Computer Science: A Structured Programming Approach Using C1 4-5 Standard Functions C provides a rich collection of standard functions whose definitions.
PHY 107 – Programming For Science. Announcements  Lectures may not cover all material from readings  Material that is most difficult or challenging.
Parallel Programming Basics  Things we need to consider:  Control  Synchronization  Communication  Parallel programming languages offer different.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
MA/CS 375 Fall 2002 Lecture 2. Motivation for Suffering All This Math and Stuff Try the Actor demo from
29 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
1 Introduction to Object Oriented Programming Chapter 10.
Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
CIS Intro to JAVA Lecture Notes Set 5 26-May-05.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Jake Blanchard University of Wisconsin Spring 2006.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
CSE 110: Programming Language I Afroza Sultana UB 1230.
Chapter 6 - Functions modular programming general function format
Matlab Introduction.
Terminal-Based Programs
Functions.
Presentation transcript:

CSCE 121: Introduction to Program Design and Concepts, Honors J. Michael Moore Spring 2015 Set 14: Plotting Functions and Data 1

CSCE 121: Set 14: Plotting Functions and Data Overview of Chapter 15 Discusses graphing of (mathematical) functions and data – Benefits of visualization – Pitfalls with floating-point approximations Introduces programming methodologies that are useful in doing so – typedef – Passing functions as arguments – Default arguments – Standard mathematical functions Graphics library as running example 2

CSCE 121: Set 14: Plotting Functions and Data Visualization It’s very useful to plot graphs of functions and data You can learn things from a plot that are not evident in a set of numbers – Think about a sine curve Visualization of data is used in most research and business areas Can communicate large amounts of data simply 3

CSCE 121: Set 14: Plotting Functions and Data Graphing Simple Functions Suppose we want to display on the screen a plot of a mathematical function, such as f(x) = 1, or f(x) = 2*x, or f(x) = x*x. We’d like to do this in a general way, so that we don’t have to write new code from scratch every time we want to plot a different function Try to pass in the (mathematical) function as an argument to a (C++) function! – Represent the mathematical function as (another) C++ function 4

CSCE 121: Set 14: Plotting Functions and Data Calling a Function that Takes a Function as an Argument Our graphics library has a type of Shape called Function (name of a class) It takes the following arguments: – A (C++) function that takes one double argument and returns a double: this calculates the mathematical function we want to plot on the screen – Range of values over which the mathematical function is to be plotted – Some other bookkeeping stuff for displaying the plot in the window After constructing a specific Function object, it can be attached to the window and displayed 5

CSCE 121: Set 14: Plotting Functions and Data Specifying an Argument that is a Function We need a type for the argument that specifies the function to be plotted Use typedef keyword, which declares a new name for a type typedef double Fct(double); Now Fct means “a function that takes a double argument and returns a double” Examples of objects of type Fct : double one(double x) { return 1;} // f(x) = 1 double slope(double x) { return x/2;} // f(x) = x/2 double square(double x) { return x*x;} // f(x) = x*x 6

CSCE 121: Set 14: Plotting Functions and Data Definition of Function Shape struct Function : Shape { // constructor Function( Fct f, // f is a (C++) function that has one // double argument and returns a double /* more arguments for controlling the display of the plot of f in the window */ ); /* rest of class description */ }; 7

CSCE 121: Set 14: Plotting Functions and Data Using Function Shape /*... */ Simple_window win(/*... */); Function plot(slope, /*... */); // remember slope was already defined win.attach(plot); win.wait_for_button(); /*...*/ 8

CSCE 121: Set 14: Plotting Functions and Data Default Arguments The Function Shape constructor has seven arguments! – Too many – Asking for trouble, confusion and error Solution: provide default values for some of the arguments – Must be “trailing” arguments 9

CSCE 121: Set 14: Plotting Functions and Data Default Arguments Example struct Function : Shape { Function( Fct f, double r1, double r2, Point xy, int count = 100, // default value of count is 100 double xscale = 25, // default value of xscale is 25 double yscale = 25); // default value of yscale is 25 }; /*... */ Function f1(sqrt,0,11,orig,100,25,25); Function f2(sqrt,0,11,orig,100); // same as f1 10

CSCE 121: Set 14: Plotting Functions and Data Standard Mathematical Functions Use #include to get access to abs, ceil, floor, sqrt, cos, sin, tan, acos, asin, atan, sinh, cosh, tanh, exp, log, log10, pow, etc. 11

CSCE 121: Set 14: Plotting Functions and Data Warning! Floating point numbers are just approximations of real numbers – Overflow – Underflow – Not precise enough for your needs – Small inaccuracies (rounding errors) can build up into huge errors Advice: – Be suspicious about calculations – Check your results 12

CSCE 121: Set 14: Plotting Functions and Data Acknowledgments Photo on slide 1: “Juhan’s 2008 Career Graph” by Juhan Sonin, licensed under CC BY 2.0“Juhan’s 2008 Career GraphJuhan SoninCC BY 2.0 Slides are based on those for the textbook: 13